Scans all request paths under the specified path (based on SPRINGMVC)

Source: Internet
Author: User
Tags set set

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.