SPRINGMVC Construction of the project, there is no integration of the persistence layer framework (Java Config configuration vs. xml configuration)

Source: Internet
Author: User

public class Webinit implements Webapplicationinitializer {@Override public void Onstartup (ServletContext container ) throws Servletexception {//project start execution://Front Controller//VS. XML configuration, config/* in Web. * * &LT;SERVL et> * <servlet-name>dispatcherServlet</servlet-name> * &LT;SERVLET-CLASS&GT;ORG.S pringframework.web.servlet.dispatcherservlet</servlet-class> * <init-param> * &L T;param-name>contextconfiglocation</param-name> * <param-value>/web-inf/classes/applicatio n.xml</param-value> * </init-param> * &LT;LOAD-ON-STARTUP&GT;1&LT;/LOAD-ON-STARTUP&G         T * </servlet> * <servlet-mapping> * <servlet-name>dispatherservlet</servlet-name&         Gt   * <url-pattern>*.do</url-pattern> * </servlet-mapping> * * *//javaconfig configuration     This sentence corresponds to the Controller core class servletregistration.dynamic dispatcherservletregistration = Container.addservlet ("Dispatcher", n        EW Dispatcherservlet ());        This is equivalent to configuring the server to start loading the servlet container dispatcherservletregistration.setloadonstartup (1); This sentence is equivalent to configuring the note driver Dispatcherservletregistration.setinitparameter ("Contextclass", "        Org.springframework.web.context.support.AnnotationConfigWebApplicationContext "); This sentence is equivalent to loading the SPRINGMVC core profile dispatcherservletregistration.setinitparameter ("Contextconfiglocation", "        Com.mike.small.config.SpringMvcConfig ");        Intercept all URLs dispatcherservletregistration.addmapping ("/");        Handling garbled filter Characterencodingfilter filter = new Characterencodingfilter ();        Filter.setencoding ("UTF-8"); Filterregistration.dynamic characterencodingfilterregistration = Container.addfilter ("CharacterEncodingFilter",        Filter); Characterencodingfilterregistration.addmappingforurlpatterns (Enumset.of (Dispatchertype.request, DispatcheRtype.forward), False, "/*");        Note Driver class Annotationconfigwebapplicationcontext Rootcontext = new Annotationconfigwebapplicationcontext ();        Rootcontext.register (Springmvcconfig.class); This is the equivalent of Web. XML Listener/*<listener> <listener-class>org.springframework.web.context.contextloade Rlistener</listener-class> </listener> * * Container.addlistener (new Contextloaderliste    NER (Rootcontext)); }}

  

@Configuration//This class contains Bean DEFINITIONS@ENABLEWEBMVC//Same as <mvc:annotation-driven/> @ComponentS Can (Basepackages = {"Com.mike.small"}) public class Springmvcconfig extends Webmvcconfigureradapter {@Override publi c void Addresourcehandlers (Resourcehandlerregistry registry) {//DECLARE static resources Registry.addresou    Rcehandler ("/static/**"). Addresourcelocations ("/static/"); } @Bean Public Internalresourceviewresolver viewresolver () {//view resolver Internalresourceview        Resolver Resolver = new Internalresourceviewresolver ();        Resolver.setprefix ("/web-inf/jsp/");        Resolver.setsuffix (". jsp");    return resolver; } @Bean Public Commonsmultipartresolver multipartresolver () {Commonsmultipartresolver multipartresolver        = new Commonsmultipartresolver ();        Multipartresolver.setmaxuploadsize (104857600);    return multipartresolver; }}

  

SPRINGMVC Construction of the project, there is no integration of the persistence layer framework (Java Config configuration vs. xml configuration)

Related Article

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.