How to scan classes for annotations?

前端 未结 7 2169
野性不改
野性不改 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> 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 :

    
        net.sf.corn
        corn-cps
        1.0.1
    
    

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

提交回复
热议问题