How to scan classes for annotations?

前端 未结 7 2064
野性不改
野性不改 2020-12-28 17:00

I have a plain jane servlets web application, and some of my classes have the following annotations:

@Controller
@RequestMapping(name = \"/blog/\")
public cl         


        
相关标签:
7条回答
  • 2020-12-28 18:05

    Try corn-cps

    List<Class<?>> classes = CPScanner.scanClasses(new PackageNameFilter("net.sf.corn.cps.*"),new ClassFilter().appendAnnotation(Controller.class));
    for(Class<?> clazz: classes){
       if(clazz.isAnnotationPresent(RequestMapping.class){
         //This is what you want
       }
    }
    

    Maven module dependency :

    <dependency>
        <groupId>net.sf.corn</groupId>
        <artifactId>corn-cps</artifactId>
        <version>1.0.1</version>
    </dependency>
    

    visit the site https://sites.google.com/site/javacornproject/corn-cps for more information

    0 讨论(0)
提交回复
热议问题