Solution to mapper injection failure problem when spring+springmvc integrate mabytis

  • 2020-10-07 18:41:21
  • OfStack

It has been a long time since we built spring+springmvc integrated mabytis. Two problems occurred today.

It took one night to solve both problems. Share your mistakes now so you don't have to jump into a pit in the future.

1. During the unit test, the unit test failed with an error: A ServletContext is required to configure default servlet handling


10 month  28, 2016 9:03:33  In the afternoon  org.springframework.context.support.GenericApplicationContext refresh
 warning : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
  at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
  at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
  at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
  at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
  at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
  at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
  at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:259)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:261)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:219)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
  ... 42 more

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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_2_5.xsd" version="2.5">
  <display-name>Archetype Created Web Application</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!--  The specified Spring Initial context - The specified spring-core The configuration file  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring_ynyn_dependence.xml</param-value>
  </context-param>

  <!--  Character encoding filter  -->
  <filter>
    <filter-name>characterEncoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- spring-mvc The distributor is configured and specified spring-mvc The configuration file  -->
  <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>

  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <servlet-name>dispatcherServlet</servlet-name>
  </filter-mapping>
</web-app>

Resources and configuration files are placed in the src/main/respources directory.

The es30EN-ES31en.xml configuration file for springMVC


<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
  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/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/util 
      http://www.springframework.org/schema/util/spring-util-3.1.xsd
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
      http://www.springframework.org/schema/task 
      http://www.springframework.org/schema/task/spring-task.xsd">


  <context:component-scan base-package="org.byron4j.ynyn.*" >
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  </context:component-scan> 

  <!--  Support for default annotation mapping  -->
  <mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
      <bean class="org.springframework.http.converter.StringHttpMessageConverter">
        <constructor-arg value="UTF-8" />
      </bean>
      <bean
        class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
        <property name="supportedMediaTypes" value="application/json;charset=UTF-8" />
        <property name="features">
          <array>
            <value>WriteMapNullValue</value>
            <value>WriteNullStringAsEmpty</value>
          </array>
        </property>
      </bean>
    </mvc:message-converters>
  </mvc:annotation-driven>

  <!--  Static resource mapping  -->
  <mvc:resources mapping="/js/**" location="/js/" />
  <mvc:resources mapping="/css/**" location="/css/" />
  <mvc:resources mapping="/images/**" location="/images/" />
  <!--  When the static resource to be accessed above is not included in the above configuration, access is based on this configuration  -->
  <mvc:default-servlet-handler />

  <!-- Resolution of the model view name by adding a presuffix to the model view name  -->
  <bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
      value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
  </bean>
</beans>

The sprin framework configuration file es37EN_ynyn_dependence.xml


<?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:aop="http://www.springframework.org/schema/aop"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.1.xsd
      http://www.springframework.org/schema/util 
      http://www.springframework.org/schema/util/spring-util-3.1.xsd
      http://www.springframework.org/schema/task 
      http://www.springframework.org/schema/task/spring-task.xsd">
  <util:properties id="valueSettings" location="classpath:globalConfig.properties" />

  <context:component-scan base-package="org.byron4j.ynyn.*" > 
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  </context:component-scan>


  <!-- Timing task annotation driver introduced, which can be used in applications @Scheduled Annotations develop timing tasks -->
  <task:annotation-driven />

  <!-- Introduce data source configuration, including mybatis Related configuration -->
  <import resource="classpath*:byron4j_ynyn_datasource.xml"/>
</beans>

Data source configuration file byron4j_ynyn_datasource.xml


<?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:aop="http://www.springframework.org/schema/aop"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx" 
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.1.xsd
      http://www.springframework.org/schema/tx  
      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:byron4j_ynyn_mybatis-config.xml" />
    <!-- The list of my items mapper.xml Files in src/main/resources directory -->
    <property name="mapperLocations" value="classpath*:sqlmap/*.xml" />
    <property name="dataSource" ref="dataSource" />
  </bean>


  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="org.byron4j.ynyn.mapper" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  </bean>

  <!--  Transaction management  -->
  <bean id="myTxManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
  </bean>

  <tx:annotation-driven transaction-manager="myTxManager" />

  <!--这里使用的是sqlite Database, yes 1 For a file database, an account with a username and password must be read-write ynyn.sqlite File permissions -->
  <bean id="dataSource" 
     class="org.apache.commons.dbcp.BasicDataSource" 
     destroy-method="close"> 
    <property name="driverClassName" value="org.sqlite.JDBC"/> 
    <property name="url" value="jdbc:sqlite:E:\ynyn.sqlite"/> 
    <property name="username" value="username"/> 
    <property name="password" value="password"/> 
    <!--maxActive:  Maximum number of connections -->  
    <property name="maxActive" value="200"/> 
    <!--minIdle:  Minimum idle connection -->  
    <property name="minIdle" value="10"/> 
    <!--maxIdle:  Maximum idle connection -->  
    <property name="maxIdle" value="50"/>
    <!--initialSize:  Initializing connection -->  
    <property name="initialSize" value="50"/> 
    <!--  Whether to print when the connection is leaked  --> 
    <property name="logAbandoned" value="true"/> 
    <!--removeAbandoned:  Whether the timeout connection is automatically reclaimed -->  
    <property name="removeAbandoned" value="true"/> 
    <!--removeAbandonedTimeout:  timeout ( In seconds )-->  
    <property name="removeAbandonedTimeout" value="180"/>
    <!--maxWait:  The timeout wait time is measured in milliseconds  1000 Is equal to the 60 seconds --> 
    <property name="maxWait" value="1000"/> 
    <!--  The value of the time to sleep while the idle connection collector thread is running , In milliseconds . --> 
    <property name="timeBetweenEvictionRunsMillis" value="10000"/> 
    <!--  At every idle connection collector thread ( If you have ) The number of connections checked at run time  --> 
    <property name="numTestsPerEvictionRun" value="10"/> 
    <!-- 1000 * 60 * 30  The connection remains idle in the pool without being idle by the connection collector thread --> 
    <property name="minEvictableIdleTimeMillis" value="10000"/> 
    <property name="validationQuery" value="SELECT 1 LIMIT 1 "/> 
  </bean>

</beans>

mybatis configuration file byron4j_ynyn_ES56en-ES57en.xml


<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
      "http://mybatis.org/dtd/mybatis-3-config.dtd">
  <configuration>

</configuration>

Unit tests the base class ES62en.java

src/test/Java


package org.byron4j.ynyn.base;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Mock Test the class base class -- Configuration files load classes 
 * 
 * @ClassName: BaseSpringTestCase
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring_ynyn_dependence.xml" })
public class BaseMockitoTestCase {
  @Before
  public void beforeInvoke() {
    System.out.println(" Pre-call work ....");
    MockitoAnnotations.initMocks(this);
  }

  @After
  public void afterInvoke() {
    System.out.println(" It completes .");
  }

}

The unit test class ES72en.java has a problem


package org.byron4j.ynyn.dbtest;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import org.byron4j.ynyn.base.BaseMockitoTestCase;
import org.byron4j.ynyn.mapper.TaskerMapper;
import org.byron4j.ynyn.mode.Tasker;



public class StudentTest extends BaseMockitoTestCase{

  @Autowired
  StudentMapper studentMapper;


  @Test
  public void selectTest4Success(){
    Student record = new Student();
    record.setId(1);
    Student resultStudent = studentMapper.selectByPrimaryKey(record);
    System.out.println(resultStudent);;
  }
}

An error warning was issued while executing the unit test: Exception encountered during context ES81en-ES82en refresh attempt
org. springframework. beans. factory. BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet config/annotation/DelegatingWebMvcConfiguration class] : Bean instantiation via factory method failed; nested exception is org. springframework. beans. BeanInstantiationException: Failed to instantiate [org. springframework. web. servlet. HandlerMapping] : Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

spring-core and springMVC, the default servlet mapper should be configured for ServletContext. 1. Confused... The context and packet scan configuration of the two configuration files were found to be defective. The springServlet context should be handled in the spring core configuration (spring_ynyn_ES163en.xml) and should be used < context:annotation-config / > Configure. The adjusted configuration is as follows:

1.sprin framework configuration file spring_ynyn_ES173en.ES174en tuning


 Configure the following 
<context:component-scan base-package="org.byron4j.ynyn.*" > 
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  </context:component-scan>
 Replace with: 
<context:annotation-config />

2.springMVC configuration file spring-ES180en.ES181en adjustment


<context:component-scan base-package="com.crfchina.mcp.*" >
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  </context:component-scan> 

Run the unit test again, OK.

2. mapper injection failure using the @ Autowired comments: nested exception is org. springframework. beans. factory. NoSuchBeanDefinitionException: No qualifying bean of type [org.byron4j.mcp.mapper.TaskerMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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_2_5.xsd" version="2.5">
  <display-name>Archetype Created Web Application</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!--  The specified Spring Initial context - The specified spring-core The configuration file  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring_ynyn_dependence.xml</param-value>
  </context-param>

  <!--  Character encoding filter  -->
  <filter>
    <filter-name>characterEncoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- spring-mvc The distributor is configured and specified spring-mvc The configuration file  -->
  <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>

  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <servlet-name>dispatcherServlet</servlet-name>
  </filter-mapping>
</web-app>
0

Solve the first problem, unit testing, deployment of the project starts, crazy error nested exception is org. springframework. beans. factory. NoSuchBeanDefinitionException: No qualifying bean of type [org.byron4j.mcp.mapper.TaskerMapper] found for dependency: 1 bean expected at least which qualifies as autowire candidate for this dependency. Dependency annotations: {@ org. springframework. beans. factory. annotation. Autowired (required = true)}. Multiple checks revealed that the springMVC configuration file also needed to load the mybatis configuration, which I did previously only in the spring context core configuration file (ES284en_ynyn_ES286en.xml).

At the end of the spring-ES291en. xml file is introduced to load the mybatis configuration:


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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_2_5.xsd" version="2.5">
  <display-name>Archetype Created Web Application</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!--  The specified Spring Initial context - The specified spring-core The configuration file  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring_ynyn_dependence.xml</param-value>
  </context-param>

  <!--  Character encoding filter  -->
  <filter>
    <filter-name>characterEncoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- spring-mvc The distributor is configured and specified spring-mvc The configuration file  -->
  <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>

  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <servlet-name>dispatcherServlet</servlet-name>
  </filter-mapping>
</web-app>
1

Unable to redeploy the application startup service, initiates a request to validate OK.


Related articles: