PackageCom.lzw.demo; @SpringBootApplication Public classDemoApplication { Public Static voidMain (string[] args) {Springapplication.run (demoapplication.class, args); } @RestController @RequestMapping (Path= "/A") Public Static classA {@GetMapping (path= "/find") Public voidAdd () {System.out.println ("Find"); } @DeleteMapping (Path= "/delete") Public voidDelete () {System.out.println ("Delete"); }} @RestController @RequestMapping (Path= "/b") Public Static classB {@PutMapping (path= "/update") Public voidUpdate () {SYSTEM.OUT.PRINTLN ("Update"); } @PostMapping (Path= "/add") Public voidAdd () {System.out.println ("Add"); } } /*** Created by Laizhenwei on 2018-1-29 22:48:49. */@Component Public Static classAppstartupImplementsCommandlinerunner {@AutowiredPrivaterequestmappinghandlermapping requestmappinghandlermapping; @Override Public voidRun (String ... strings) {Class<annotation>[] Annoclz =NewClass[]{requestmapping.class, postmapping.class, getmapping.class, DeleteMapping.class, putmapping.class}; Map<requestmappinginfo, handlermethod> map =Requestmappinghandlermapping.gethandlermethods (); List<Class<?>> beantypes =Map.keyset (). Stream (). Filter (Info-Map.get (info). Getbeantype (). Getannotation (requestmapping.class) !=NULL). Collect (Collectors.tolist ()). Stream (). Map (i-Map.get (i). Getbeantype ()). Collect (Collectors.tolist ()); Beantypes.foreach (tArrays.stream (T.getmethods ()). ForEach (Method- { for(inti = 0; i < annoclz.length; i++) {Annotation Mappinganno=method.getannotation (Annoclz[i]); if(Mappinganno! =NULL) { Try{Invocationhandler Invocationhandler=Proxy.getinvocationhandler (Mappinganno); Field value= Invocationhandler.getclass (). Getdeclaredfield ("Membervalues"); Value.setaccessible (true); Map<string, object> membervalues = (map<string, object>) Value.get (Invocationhandler); System.out.println (Arrays.tostring ((string[) Membervalues.get ("Path")))); } Catch(Exception ex) {ex.printstacktrace (); } } } } )); } }}
Java obtains annotation parameters when unsure of the specific Annotation type