🎊 SSM框架的几个重要配置文件

SSM框架的几个重要配置文件

这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文件并没有进行过多的说明,很多人知其然不知其所以然,经过几天的搜索和整理,今天总算对其中的XML配置文件有了一定的了解,所以拿出来一起分享一下,希望有不足的地方大家批评指正~~~

首先 这篇文章暂时只对框架中所要用到的配置文件进行解释说明,而且是针对注解形式的,框架运转的具体流程过两天再进行总结.

spring+springmvc+mybatis框架中用到了三个XML配置文件:web.xml,spring-mvc.xml,spring-mybatis.xml.第一个不用说,每个web项目都会有的也是关联整个项目的配置.第二个文件spring-mvc.xml是springmvc的一些相关配置,第三个是mybatis的相关配置.

项目中还会用到两个资源属性文件jdbc.properties和log4j.properties.一个是关于jdbc的配置,提取出来方便以后的修改.另一个是日志文件的配置.

以上是我这篇文章中所要讲的内容,比较简单,也很容易懂.希望大牛不要鄙视~~接下来进入正题:

一 web.xml

关于这个配置文件我以前一直都是朦朦胧胧的状态,刚好借着这次整合框架的机会将它了解清楚.在下面的代码中我对每一个标签都进行了详细的注释,大家一看就懂,主要理解中的配置,因为其中配置了前端控制器,在SSM框架中,前端控制器起着最主要的作用.下面贴上代码

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”>

contextConfigLocation

classpath:spring-mybatis.xml

> context-param >> listener >> filter >> servlet >> spring–>

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

true

encoding

UTF-8

encodingFilter

/*

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

SpringMVC

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

true

SpringMVC

/

120

*.ppt

application/mspowerpoint

/index.jsp 指定几个首页,而服务器会依照设定的顺序来找首页.–>

/index.html

404

error.html

java.lang.Exception

ExceptionError.html

二 spring-mvc.xml

需要实现基本功能的配置 1 配置 2 配置 //配置controller的注入3 配置视图解析器

相当于注册了DefaultAnnotationHandlerMapping(映射器)和AnnotationMethodHandlerAdapter(适配器)两个bean.即解决了@Controller注解的使用前提配置。

context:component-scan 对指定的包进行扫描,实现注释驱动Bean定义,同时将bean自动注入容器中使用。即解决了@Controller标识的类的bean的注入和使用。

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns:aop=“http://www.springframework.org/schema/aop”

xmlns:mvc=“http://www.springframework.org/schema/mvc”

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-4.1.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-4.1.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-4.1.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-4.1.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd”>

三 spring-mybatis.xml

需要实现基本功能的配置 1 配置 //自动扫描,将标注Spring注解的类自动转化Bean,同时完成Bean的注入2 加载数据资源属性文件3 配置数据源 三种数据源的配置方式 http://blog.csdn.net/yangyz_love/article/details/81992074 配置sessionfactory5 装配Dao接口6 声明式事务管理 7 注解事务切面

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-4.1.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-4.1.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-4.1.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-4.1.xsd">

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

destroy-method="close">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

下面是需要引入的两个资源属性文件:

jdbc.properties

driver=com.mysql.jdbc.Driver

url=jdbc:mysql://127.0.0.1:3306/ecdatabase?characterEncoding=utf-8

username=root

password=admin

#定义初始连接数

initialSize=0

#定义最大连接数

maxActive=20

#定义最大空闲

maxIdle=20

#定义最小空闲

minIdle=1

#定义最长等待时间

maxWait=60000

driver=com.mysql.jdbc.Driver

url=jdbc:mysql://127.0.0.1:3306/ecdatabase?characterEncoding=utf-8

username=root

password=admin

log4j.properties

#定义LOG输出级别

log4j.rootLogger=INFO,Console,File

#定义日志输出目的地为控制台

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.Target=System.out

#可以灵活地指定日志输出格式,下面一行是指定具体的格式

log4j.appender.Console.layout = org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n

#文件大小到达指定尺寸的时候产生一个新的文件

log4j.appender.File = org.apache.log4j.RollingFileAppender

#指定输出目录

log4j.appender.File.File = logs/ssm.log

#定义文件最大大小

log4j.appender.File.MaxFileSize = 10MB

# 输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志

log4j.appender.File.Threshold = ALL

log4j.appender.File.layout = org.apache.log4j.PatternLayout

log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

🎁 相关推荐

《DNF》师傅通宝获取攻略
🎯 世界杯365bet

《DNF》师傅通宝获取攻略

📅 10-11 👀 2255
君子兰换盆时间和方法,换盆后如何浇水
🎯 世界杯365bet

君子兰换盆时间和方法,换盆后如何浇水

📅 08-20 👀 1711
win10和win8双系统安装
🎯 365官网登录

win10和win8双系统安装

📅 10-29 👀 7059