public class Webinit implements Webapplicationinitializer {@Override public void Onstartup (ServletContext container ) throws Servletexception {//project start execution://Front Controller//VS. XML configuration, config/* in Web. * * <SERVL et> * <servlet-name>dispatcherServlet</servlet-name> * <SERVLET-CLASS>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> * <LOAD-ON-STARTUP>1</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)