[Spring MVC]-Spring MVC Environment Setup

Source: Internet
Author: User

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

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.