模拟Spring中扫描注解的代码

模拟Spring中扫描注解的代码

File[] files = new File("D:/code/02-tanzhouedu/tz_springmvc/src/com/tz/dao").listFiles();
for (File file : files) {
	String filename = StringUtils.cleanPath(file.getAbsolutePath());
	String name = filename.replaceAll("D:/code/02-tanzhouedu/tz_springmvc/src/", "").replaceAll("/", ".").replace(".java", "");
	Class clz = Class.forName(name);
	Object obj = clz.newInstance();
	Annotation component =clz.getAnnotation(Component.class);
	if(component!=null){
		//注册到applicationContext
	}
}

猜你喜欢

转载自lipiaoshui2015.iteye.com/blog/2265022