Through the two blogs above, we were able to get all the request paths on the specified class. What is needed now is to get the full request path given a specified path.
Public classRequesturlscannerhelper {/*** The following three parameters are injected through the IOC*/ PrivateString Basepackage;//Scan the base package PrivateResourcepatternresolver Resolver;//Parser PrivateTypeFilter Controlfilter =NewAnnotationtypefilter (Controller.class,false); PrivateString pattern; PrivateSet<class<?>> Matchcontrolerclass =NewHashset<class<?>>(); /*** According to Basepackage get all the class files and match, will satisfy the condition of the class storage and set set. * @throwsIOException *@throwsclassnotfoundexception*/@PostConstruct Public voidInit ()throwsIOException, classnotfoundexception {pattern= Resourcepatternresolver.classpath_all_url_prefix + Classutils.convertclassnametoresourcepath (basePackage) + "/**/ *.class "; Resource[] Resources=resolver.getresources (pattern); Metadatareaderfactory Factory=Newcachingmetadatareaderfactory (resolver); for(Resource resource:resources) {if(Resource.isreadable ()) {Metadatareader Reader=Factory.getmetadatareader (Resource); if(Controlfilter.match (reader, Factory)) {Matchcontrolerclass.add (Class.forName (Reader.getclassmetad ATA (). GetClassName ())); } } } } PublicString getbasepackage () {returnBasepackage; } Public voidsetbasepackage (String basepackage) { This. Basepackage =Basepackage; } Publicresourcepatternresolver Getresolver () {returnResolver; } Public voidsetresolver (resourcepatternresolver resolver) { This. Resolver =Resolver; } /** * * @returnspecifies all request information under the package. * @throwsnosuchmethodexception *@throwsSecurityException *@throwsillegalaccessexception *@throwsIllegalArgumentException *@throwsinvocationtargetexception*/ PublicList<requesturlinfo> Getallrequesturl ()throwsnosuchmethodexception, SecurityException, Illegalaccessexception, IllegalArgumentException, invocationtargetexception {List<RequestUrlInfo> infos =NewArraylist<requesturlinfo>(); for(class<?>Scannerclass:matchcontrolerclass) {Infos.addall (Requesturlhelper.getinstance (). Getallrequesturlinfos (Scannerclass)); } returninfos; }}
Scans all request paths under the specified path (based on SPRINGMVC)