annotation 인스턴스

1376 단어 annotation

지정한 디렉터리의 모든class를 불러옵니다. 주석을 통해 실체 클래스를 구분합니다.
package com.annotation.annoBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.annotation.HBID;
import com.annotation.HBean;
import com.tools.ClassLoaderUtil;

public class AnnotationBeanLoader {
	
	private static String beanRootPath = "/com/annotation";//bean root
	
	public static Map<String,Class<HBean>> loadHandlerBean() throws Exception{
		Map<String, Class<HBean>> beanMap = new HashMap<String, Class<HBean>>();
		List<Class<?>> classes = ClassLoaderUtil.loadClassesFromPath(beanRootPath);
    	for (int i = 0; i < classes.size(); i++) {
    		Class<?> c = classes.get(i);
    		if(classes.get(i).isAnnotationPresent(HBID.class)){
    			HBID hbid = classes.get(i).getAnnotation(HBID.class);
    			String id = hbid.catalog()+"-"+hbid.id();
    			if(c.isAssignableFrom(HBean.class))
    				beanMap.put(id, (Class<HBean>) c);
    		}
		}
		return beanMap;
	}

}

 
하위 클래스를 가져오려면 다음과 같이 하십시오.
http://blackproof.iteye.com/blog/2015036

좋은 웹페이지 즐겨찾기