简体   繁体   中英

Inject logic into spring component scanning process

So it is possible to use <context:component-scan ...> or @ComponentScan("org.rythmengine.spring.web") to allow spring to scan beans under certain package. The question is how can I inject my logic during the scanning process? Say I want to leverage spring's scanning to find all classes implemented a certain interface, or annotated with a certain annotation.

For scanning/detecting components I suggest taking a look at how <context:component-scan /> and LocalSessionFactoryBean scan for components or entities. Both use the same underlying mechanism for detecting classes.

As for the @CacheFor annotation I would suggest leveraging Spring AOP just the same as spring uses for @Transactional and @Cacheable (to name just 2 appliances).

Ofcourse you can place everything nicely behind a namespace just like <tx:annotation-driven /> or <cache:annotation-driven /> . That is all explained in this section of the reference guide.

Links

  1. Scanning for entities source | source
  2. Develop custom namespace reference
  3. AOP with Spring reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM