SpringMVC development environment to build

1. dependencies:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>5.1.7.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>5.1.7.RELEASE</version>
</dependency>

2. SpringMVC profile:

  Create a "spring / application.xml" configuration file in the "src \ main \ resources" source code directory;

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvn="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <! - Pack scan ->
    <context:component-scan base-package="cn.ll.action" />
    <! - Enable control layer notes ->
    <mvn:annotation-driven />
    <! - processing request using Dispatcher ->
    <mvn:default-servlet-handler />
    <! - definition page analysis processing resource class, the prefix matching the path suffix ->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <! - is stored in the WEB-INF static resource access path mapping settings ->
    <mvn:resources mapping="/js/**" location="/WEB-INF/js/" />
    <mvn:resources mapping="/css/**" location="/WEB-INF/css/" />
    <mvn:resources mapping="/images/**" location="/WEB-INF/images/" />
    <! - were to be loaded "* .properties" configuration file path load, CLASSPATH loaded directly by ->
    <bean class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <array>
                <value>cn.ll.redis.message.pages</value>
                <value>cn.ll.redis.message.message</value>
            </array>
        </property>
    </bean>
    <-! Upload configuration file parsing process category ->
    <bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <! - set the overall maximum amount of data uploaded files, this allows a maximum file upload capacity of 5M ->
        <property name="maxUploadSize" value="5242880"/>
        <! - set the maximum amount of data of a single file upload this file the maximum amount allowed to upload 2M ->
        <property name="maxUploadSizePerFile" value="253952"/>
        <! - the maximum allowable amount of memory footprint, this is set to 10M ->
        <property name="maxInMemorySize" value="10485760"/>
        <-! Temporary directory where you saved the upload file, the contents of the directory after each request will need to be emptied ->
        <property name="uploadTempDir" value="/tmp"/>
    </bean>
    <! - Configure the global jump page ->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
        <Property name = "exceptionMappings"> <-! Exception mapping ->
            <props>
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">plugins/errors</prop>
            </props>
        </property>
    </bean>
</beans>

3. Configure web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <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/application.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>
    <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

 

Guess you like

Origin www.cnblogs.com/luliang888/p/11074588.html