码迷,mamicode.com
首页 > 编程语言 > 详细

spring-mybatis-springMVC 整合

时间:2018-03-24 17:54:13      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:nbsp   doctype   uid   png   map   load   enc   list   监听器   

这是一个spring mybatis springMVC 的整合 里面包括日志,druid,的配置。可以说是一个现成的模板,直接复制下来就能用。


首先是web.xml

web.xml 中包括

  • Spring beans 配置文件所在目录
  • utf-8编码过滤器
  • spring的监听器
  • springmvc的配置
  • druid的配置
  • 默认的首页index

这里说一下,springmvc没有指定springmvc的配置文件的位置,因为springmvc默认是去web-info文件夹下找spring-servlet.xml的配置文件的。需要注意一下。这里配置druid是因为我们要利用durid来监测我们访问的url,

durid是一个非常出色数据库连接池。非常的强大,他自带的有监控界面,需要配置一下。

技术分享图片
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <!-- Spring beans 配置文件所在目录 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Encoding -->
    <filter>
        <filter-name>encodingFilter</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>
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <init-param>
            <param-name>exclusions</param-name>
            <param-value>*.js,*.css,*.jpg,*.png,*.ico,*.gif,/sys/druid/*</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- spring mvc 配置 -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <!-- druid -->
    <servlet>
        <servlet-name>DruidStatServlet</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
        <init-param>
            <param-name>loginUsername</param-name>
            <param-value>druid</param-value>
        </init-param>
        <init-param>
            <param-name>loginPassword</param-name>
            <param-value>druid</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>DruidStatServlet</servlet-name>
        <url-pattern>/sys/druid/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>
View Code

 

spring-mybatis-springMVC 整合

标签:nbsp   doctype   uid   png   map   load   enc   list   监听器   

原文地址:https://www.cnblogs.com/coder-lzh/p/8640470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!