java - 利用spring如何扫描到所有自定义注解,并进行某些操作
巴扎黑
巴扎黑 2017-04-18 09:46:44
0
7
412

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

巴扎黑
巴扎黑

reply all(7)
Peter_Zhu

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

刘奇

Configure in springmvc configuration file

阿神

Already found a way. I am using spring-boot. Write a class that inherits ApplicationListener<ContextRefreshedEvent>
Then use event.getApplicationContext().getBeansWithAnnotation(TableBind.class); That’s it
Thank you everyone

小葫芦

Custom annotations can only be implemented using aop in spring.

伊谢尔伦
<context:component-scan base-package="com.togeek.**.service.imple" />
PHPzhong

For spring-boot
just inject it in the startup class
For example:
@ComponentScan(basePackages = "customer.common") //Specify the controller you want to scan here
@SpringBootApplication
public class CustomerMain{

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

}

巴扎黑

In fact, the final package and class must be stored and abstracted into files, so traversing classes becomes traversing folders and files.

There is an example, you can take a look
http://changhongbao.iteye.com...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!