Spring+SpringMvc+Mybatis整合注意事项

Posted FJJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring+SpringMvc+Mybatis整合注意事项相关的知识,希望对你有一定的参考价值。

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_3_0.xsd"  
    version="3.0">  
    <display-name>Archetype Created Web Application</display-name>  
    <!-- Spring和mybatis的配置文件 -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:spring-mybatis.xml</param-value>  
    </context-param>  
    
   
    <!-- 编码过滤器 -->  
    <filter>  
        <filter-name>encodingFilter</filter-name>  
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
        <async-supported>true</async-supported>  
        <init-param>  
            <param-name>encoding</param-name>  
            <param-value>UTF-8</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>encodingFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
    <!-- Spring监听器 -->  
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
    <!-- 防止Spring内存溢出监听器 -->  
    <listener>  
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
    </listener>  
  
    <!-- Spring MVC servlet -->  
    <servlet>  
        <servlet-name>SpringMVC</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>  
        <async-supported>true</async-supported>  
    </servlet>  
    <servlet-mapping>  
        <servlet-name>SpringMVC</servlet-name>  
        <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 这里代表拦截如下两种后缀的请求,如果只写 /,那么代表拦截所有资源 -->  
        <url-pattern>*.json</url-pattern>  
        <url-pattern>*.jhtml</url-pattern> 
    </servlet-mapping>  
    <welcome-file-list>  
        <welcome-file>/index.jsp</welcome-file>  
    </welcome-file-list>  
  
</web-app>  

 <!-- 读取spring和shiro配置文件 -->
<!--     <context-param> -->
<!--         <param-name>contextConfigLocation</param-name> -->
<!--         <param-value>classpath:spring-shiro.xml</param-value> -->
<!--     </context-param> -->
    <!-- 设计路径变量值 -->
<!--     <context-param> -->
<!--         <param-name>webAppRootKey</param-name> -->
<!--         <param-value>springmvc.root</param-value> -->
<!--     </context-param> -->
    
    <!-- shiro过滤器 -->
<!--     <filter> -->
<!--         <filter-name>shiroFilter</filter-name> -->
<!--         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> -->
<!--         <init-param> -->
<!--             <param-name>targetFilterLifecycle</param-name> -->
<!--             <param-value>true</param-value> -->
<!--         </init-param> -->
<!--     </filter> -->
<!--     <filter-mapping> -->
<!--         <filter-name>shiroFilter</filter-name> -->
<!--         <url-pattern>*.jhtml</url-pattern> -->
<!--         <url-pattern>*.json</url-pattern> -->
<!--     </filter-mapping> -->

 

以上是关于Spring+SpringMvc+Mybatis整合注意事项的主要内容,如果未能解决你的问题,请参考以下文章

SpringMVC不停加载Mybatis的mapper

Spring和mybatis整合 org.mybatis.spring.mapper.MapperScannerConfigurer

SSM的整合

Spring - SpringMVC - MyBatis

Spring+SpringMVC+Mybatis+Mysql整合实例

Spring+SpringMVC+Mybatis+Mysql整合实例