1) Copy the Lib package required by spring
(This is the Lib package required by SSH, if you only use spring, you can remove some packages)
2) Configure Web. xml
<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "3.0"xmlns= "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_3_0.xsd"> <Display-name>Test Spring MVC-1</Display-name> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring.xml</Param-value> </Context-param> <servlet> <Servlet-name>Dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value></Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Dispatcher</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <welcome-file-list> <Welcome-file>index.jsp</Welcome-file> </welcome-file-list></Web-app>
Here, Classpath:spring.xml, means using Spring.xml as a profile. The document is placed under SRC.
This way, using spring+spring MVC, you can unify a configuration file.
3) Spring.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.0.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-3.0.xsd "> <!--Annotation Description - <Context:annotation-config/> <!--support for the default annotation mappings - <Mvc:annotation-driven/> <!--converts a class marked with a @controller annotation to a bean - <Context:component-scanBase-package= "com.my" /> <!--View Interpretation Class - <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value= "/web-inf/views/"/> < Propertyname= "suffix"value= ". jsp"/><!--can be empty, easy to implement the self-based extension to select the view to interpret the logic of the class - < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView" /> </Bean> </Beans>
These configurations are required.
Annotation is used here, no configuration method uses spring MVC
[Spring MVC]-Spring MVC Environment Setup