首页 > 利用spring如何扫描到所有自定义注解,并进行某些操作

利用spring如何扫描到所有自定义注解,并进行某些操作

hi,各位好
我在自己实现一个controller框架的时候遇到一个问题,我想和spring mvc 一样利用注解来实现url mapping。但是前提是我必须在程序加载的时候必须要扫扫描到所有的自定义注解。然后进行url mapping的处理。
现在问题是我如何通过spring扫描指定package下的所有类,然后判断是不是有该注解进而去做相应的处理。
判断有没有注解什么的我都清楚,现在不清楚的就是如何通过spring来扫描指定package下的所有类,然后用自己的方法处理这些类。
多谢大家


在springmvc的配置文件中配


http://m.yl1001.com/group_article/3061468659121307.htm?shcd=kadkdundaub


<context:component-scan base-package="com.togeek.**.service.imple" />

spring-boot 的话
在启动类中 注进去就好
例如:
@ComponentScan(basePackages = "customer.common") //这里指定你要扫描的 controller
@SpringBootApplication
public class CustomerMain{

public static void main(String[] args){
    SpringApplication.run(CustomerMain.class, args);
}

}


自定义注解在spring里面只能用aop实现。


已经找到方法了。我用的是spring-boot。写一个类继承ApplicationListener<ContextRefreshedEvent>
然后用event.getApplicationContext().getBeansWithAnnotation(TableBind.class);即可
多谢大家

【热门文章】
【热门文章】