The SPRINGMVC environment primarily requires spring's core Libraries and Web Libraries, which can be added directly using MyEclipse. Note: Use the official lib when you need to add Com.springsource.org.apache.commons.logging-1.1.1.jar, otherwise you will get an error.
Spring-mvc.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.1.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring- Tx-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-co Ntext-3.1.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1 . xsd "> <!--activate tags such as @required @Autowired @Resource -<Context:annotation-config/><!--Dispatcherservlet context, specifying the class to scan for controller annotations -<Context:component-scanBase-package= "Com.demo"><Context:include-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller"/></Context:component-scan> <!--support for the default annotation mappings - <Mvc:annotation-driven/> <!--Specify the directory of the view and the suffix of the file -<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value= "/web-inf/jsp/"/> < Propertyname= "suffix"value= ". jsp"/></Bean></Beans>
Applicationcontext.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:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"></Beans>
Xml
<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0"> <Display-name>Springmvc</Display-name> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <servlet> <Servlet-name>Mvc-dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <!--Dispatcherservlet The corresponding context configuration - <!--The following specifies the location of the loaded Mvc-dispatcher-servlet.xml - <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>/web-inf/configs/spring-mvc.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Mvc-dispatcher</Servlet-name> <!--Configure the type of interception request - <Url-pattern>/</Url-pattern> </servlet-mapping> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:applicationContext.xml</Param-value> </Context-param></Web-app>
Demo.java
Package Com.demo; Import Org.springframework.stereotype.Controller; Import org.springframework.web.bind.annotation.RequestMapping, @Controller @requestmapping ("/hello") Public class Demo { @RequestMapping ("/one") public String Hello () { return "Hello";}}
This is primarily the writing of these three profiles, and then placing the JSP file in the corresponding folder. The last access path is:/HTTP server address: Port/requestmapping of the requestmapping/method of the project name/class
SPRINGMVC Environment Configuration