SpringMvc4.2.5 0 Configuration appears No mapping found for HTTP request with URI

Source: Internet
Author: User

Original address: SpringMvc4.2.5 0 configuration appears No mapping found for HTTP request with URI

Using the spring 0 configuration, refer to the Http://hanqunfeng.iteye.com/blog/2113820,WebInitializer class code as follows:

 Public classWebinitializerImplementsWebapplicationinitializer {Private Static FinalLogger Logger = Logmanager.getlogger (Webinitializer.class); @Override Public voidOnstartup (ServletContext ServletContext)throwsservletexception {logger.info ("--------> Start Web App"); /** log4jconfiglistener:log4j 2nd log configuration, configuration file is Classpath:log4j2.xml*/Servletcontext.addlistener (NewLog4jservletcontextlistener ()); Log4jservletfilter Log4jservletfilter=NewLog4jservletfilter (); Servletcontext.addfilter ("Log4jservletfilter", Log4jservletfilter); /** Opensessioninviewfilter: Add this filter to ensure that Jackson can serialize the lazy fetchtype*/Opensessioninviewfilter Opensessioninviewfilter=NewOpensessioninviewfilter (); Filterregistration.dynamic opensessioninviewfilterregistration=ServletContext. addfilter ("Opensessioninviewfilter", Opensessioninviewfilter); //Specifies the sessionfactory configured in springOpensessioninviewfilterregistration.setinitparameter ("Sessionfactorybeanname", "Sessionfactory"); //singlesession defaults to True, and setting to False equals useless opensessioninviewOpensessioninviewfilterregistration.setinitparameter ("Singlesession", "true"); Opensessioninviewfilterregistration.addmappingforurlpatterns (Enumset.of (Dispatchertype.request, Dispatch Ertype.forward, Dispatchertype.include),false, "/"); Serverparameter params=serverparameter.getinstance ();        Dbmananger.loadenv (); if(Dbmananger.conndb ()) {//The database connection is successful and then loaded into the app configurationParams.addattribute ("Conndbsataus",true); /** AppConfig class for configuration outside of spring MVC*/Annotationconfigwebapplicationcontext Rootcontext=NewAnnotationconfigwebapplicationcontext (); Rootcontext.register (AppConfig.class); Servletcontext.addlistener (NewContextloaderlistener (Rootcontext)); }        /** SPRING-MVC Context*/Annotationconfigwebapplicationcontext Springmvccontext=NewAnnotationconfigwebapplicationcontext ();//Springmvccontext.register (mvcconfig.class);        /** Dispatcherservlet*/Dispatcherservlet Dispatcherservlet=NewDispatcherservlet (Springmvccontext); Servletregistration.dynamic Dynamic= Servletcontext.addservlet ("Dispatcherservlet", Dispatcherservlet); Dynamic.setloadonstartup (1); Dynamic.addmapping ("/"); /** Characterencodingfilter: Solve Chinese garbled problem*/Characterencodingfilter Characterencodingfilter=NewCharacterencodingfilter (); Characterencodingfilter.setencoding ("Utf-8"); Filterregistration characterencodingfilterregistration=Servletcontext.addfilter ("Characterencodingfilter", Characterencodingfilter); Characterencodingfilterregistration.addmappingforurlpatterns (Enumset.of (dispatchertype.request),false, "/*"); }}

The Mvcconfig configuration is as follows:

 Public classMvcconfigextendsWebmvcconfigurationsupport {Private Static FinalLogger Logger = Logmanager.getlogger (mvcconfig.class); /*** Register View processor *@return     */@Bean Publicviewresolver Viewresolver () {Logger.info ("Register View processor-------->viewresolver"); Internalresourceviewresolver Viewresolver=NewInternalresourceviewresolver (); Viewresolver.setprefix ("/jsp/"); Viewresolver.setsuffix (". JSP"); returnViewresolver; }    /*** Resource Access Processor * can access content under/images/in a JSP using/images/***/@Override Public voidaddresourcehandlers (Resourcehandlerregistry registry) {Logger.info ("Resource access processor-------->addresourcehandlers"); Registry.addresourcehandler ("/resources/**"). Addresourcelocations ("/resources/"). Resourcechain (true). Addresolver (NewVersionresourceresolver (). Addcontentversionstrategy ("/**")); }}

The result appears no mapping found for HTTP request with URI warning, 404 error when accessing static resources.

After debugging, it is found that the following bean is added to the Mvcconfig class to solve the problem

    @Bean      public  handlermapping resourcehandlermapping () {          logger.info (" Handlermapping ");           return Super . resourcehandlermapping ();      }

Why explicitly declaring the bean is unknown.

In addition, if annotated in the Mvcconfig class, @Configuration, configure in the Webinitializer class

        New Annotationconfigwebapplicationcontext ();        Springmvccontext.register (mvcconfig. class);

Will cause Mvcconfig to load two times and can comment out one side.

SpringMvc4.2.5 0 Configuration appears No mapping found for HTTP request with URI (RPM)

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.