5.IDEA new project with the spring framework with MAVEN
1. Create a new Web project using the MAVEN skeleton
1.1 New Web Project
1.2 Create a new package and make a good file type
1.3 Add framework support (this article core, not recommended to manually add framework support)
2. Add support for the Spring framework and add a blank configuration file
3. Configure Web. XML (in addition to the core configuration of SPRINGMVC, if you do not need to inherit spring, other configurations can not be added)
<?XML version= "1.0" encoding= "UTF-8"?><Web-appxmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version= "2.5"> <!--1. Join the spring and MyBatis configuration files - <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring-mybatis.xml</Param-value> </Context-param><!--2. Configure Spring Listener: Read JavaBean in the configuration file - <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener><!--3. Load the SPRINGMVC Core controller: All requests are allocated by this controller for processing - <servlet> <Servlet-name>Dispatcherservlet</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring-mvc.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Dispatcherservlet</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <!--4. Configure character encoding to solve Chinese garbled problem: Post request only - <Filter> <Filter-name>Characterencodingfilter</Filter-name> <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class> <Init-param> <Param-name>Encoding</Param-name> <Param-value>UTF-8</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Characterencodingfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping></Web-app>
4. Configure Spring-mvc.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:jee= "Http://www.springframework.org/schema/jee"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc.xsd/HTTP Www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd/HTTP Www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!--1. Configure scanning for the business layer - <Context:component-scanBase-package= "Nick.controller"/> <Context:component-scanBase-package= "Nick.service"/> <Context:component-scanBase-package= "Nick.dao"/> <!--2. Enable Annotations - <Mvc:annotation-driven/> <!--3. Configure the View forwarder - <BeanID= "Viewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value="/" /> < Propertyname= "suffix"value= ". jsp" /> </Bean></Beans>
5. Configure now, then use Tomcat to configure, run up test
6.IDEA new project with the spring framework with MAVEN