SSM(Spring+Spring MVC+Mybatis)环境框架搭建与配置详解

本文详细介绍了SSM(Spring+Spring MVC+Mybatis)框架的搭建过程,包括环境配置、配置文件详解、架构设计以及测试步骤。通过web.xml、spring-mvc.xml和spring-servlet.xml等配置文件的解析,帮助读者理解SSM集成的关键点。
摘要由CSDN通过智能技术生成

版权声明:本文为博主原创文章,未经博主允许不得转载。


一、简介

使用SSM框架做了一些项目,一直都是使用别人已经搭建好的框架。于是自己尝试着搭建了一下框架,并研究了一下配置文件。


基本的组织结构和用法就不用多说了,各种官方文档上比较全面


二、环境与框架


开发环境MyEclipse+JDK1.7+Tomcat7

开发环境配置请查阅博客


本文按照开发环境搭建,完整的结构框架如下





三、配置文件详解

1.web.xml

web.xml应该是整个项目中最重要的配置文件了,配置方式与普通的servlet基本相似

<span style="font-size:14px;">  <servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:resources/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping></span>

servlet 配置前端控制器,其中

ContextconfigLocation配置配置springmvc加载的配置文件适配器、处理映射等等

url-pattern中 .* :访问以.*结尾 由DispatcherServlet进行解析

/  :所有访问由DispatcherServlet进行解析


配置Spring容器:

<span style="font-size:14px;">  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:resources/spring-mvc.xml</param-value>
  </context-param></span>
配置日志文件:

<span style="font-size:14px;">  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>60000</param-value>
  </context-param></span>

配置监听器:

<span style="font-size:14px;">  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener></span>


配置容器编码为utf-8:

<span style="font-size:14px;">  <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-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping></span>

配置处理错误页面:

<span style="font-size:14px;"><error-page>
<span style="white-space:pre">	</span><exception-type>java.lang.Throwable</exception-type>
<span style="white-space:pre">	</span><location>/error.jsp</location>
</error-page>
<error-page>
<span style="white-space:pre">	</span><error-code>404</error-code>
<span s
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值