spring+spring mvc+mybatis配置

2 篇文章 0 订阅
1 篇文章 0 订阅

当前常用的框架是ssm(spring+spring mvc+mybatis),现将其基本配置整理如下:

1.通过maven导入项目所需要的jar包

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.creditease.cams2.ph</groupId>
  <artifactId>cams2.ph</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>cams2_ph</name>
  <description>档案管理系统(普惠端)</description>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
    <!-- 通过maven_install最终生成的war包名称 -->
    <finalName>cams2_ph</finalName>
    <resources>
    	<resource>
    		<directory>src/main/resources</directory>
    	</resource>
    	<resource>
    		<directory>src/main/java</directory>
    		<includes>
    			<include>*.xml</include>
    		</includes>
    	</resource>
    </resources>
  </build>
  
  <properties>
  	<!-- 指定maven通过什么字符集来构建项目 -->
  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <repositories>
  	<!-- 指定maven仓库地址(宜信内服) -->
  	<repository>
  		<id>releases</id>
  		<name>Releases</name>
  		<url>http://10.100.31.71:8080/nexus/content/groups/public</url>
  	</repository>
  </repositories>
  
  <pluginRepositories>
  	<!-- 指定maven插件仓库地址(宜信内服) -->
  	<pluginRepository>
  		<id>releases</id>
  		<name>Releases</name>
  		<url>http://10.100.31.71:8080/nexus/content/groups/public</url>
  	</pluginRepository>
  </pluginRepositories>
  
  <!-- 技术框架spring+struts2+mybatis所依赖的jar包 -->
  <dependencies>
  	<!-- spring依赖 -->
  	<!-- aspects -->
  	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-aspects</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- beans -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-beans</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- aop -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-aop</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- web -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-web</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- webmvc -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-webmvc</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- webmvc-portlet -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-webmvc-portlet</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- core -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-core</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- test -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-test</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- context -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-context</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- jdbc -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-jdbc</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- tx -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-tx</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- context-support -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-context-support</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- expression -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-expression</artifactId>
    	<version>4.2.5.RELEASE</version>
	</dependency>
	<!-- orm -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-orm</artifactId>
    	<version>4.2.5.RELEASE</version>
    </dependency>
	<!-- spring-struts -->
	<dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-struts</artifactId>
    	<version>3.2.16.RELEASE</version>
	</dependency>
  	<!-- struts2依赖 -->
  	<!-- core -->
  	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-core</artifactId>
    	<version>2.3.28</version>
	</dependency>
	<!-- struts2-spring -->
	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-spring-plugin</artifactId>
    	<version>2.3.28</version>
	</dependency>
	<!-- struts2-json -->
	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-json-plugin</artifactId>
    	<version>2.3.28</version>
	</dependency>
	<!-- struts2-junit -->
	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-junit-plugin</artifactId>
    	<version>2.3.28</version>
	</dependency>
	<!-- struts2-convention -->
	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-convention-plugin</artifactId>
    	<version>2.3.28</version>
	</dependency>
  	<!-- mybatis依赖 -->
  	<!-- mybatis-spring -->
  	<dependency>
    	<groupId>org.mybatis</groupId>
    	<artifactId>mybatis-spring</artifactId>
    	<version>1.2.4</version>
	</dependency>
	<!-- core -->
	<dependency>
    	<groupId>org.mybatis</groupId>
    	<artifactId>mybatis</artifactId>
    	<version>3.3.1</version>
	</dependency>
	<!-- docbook -->
	<dependency>
    	<groupId>org.mybatis</groupId>
    	<artifactId>mybatis-docbook</artifactId>
    	<version>1.0.0</version>
	</dependency>
  	<!-- java依赖 -->
  	<!-- 单元测试依赖(junit) -->
  	<dependency>
    	<groupId>junit</groupId>
    	<artifactId>junit</artifactId>
    	<version>4.12</version>
	</dependency>
  	<!-- 导入导出依赖(poi) -->
  	<!-- core -->
  	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi</artifactId>
    	<version>3.14</version>
	</dependency>
	<!-- ooxml-schemas -->
	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi-ooxml-schemas</artifactId>
    	<version>3.14</version>
	</dependency>
	<!-- ooxml -->
	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi-ooxml</artifactId>
    	<version>3.14</version>
	</dependency>
	<!-- examples -->
	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi-examples</artifactId>
    	<version>3.14</version>
	</dependency>
	<!-- security -->
	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>ooxml-security</artifactId>
    	<version>1.1</version>
	</dependency>
	<!-- schemas -->
	<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>ooxml-schemas</artifactId>
    	<version>1.3</version>
	</dependency>
  	<!-- 应用服务器依赖(tomcat) -->
  	<!-- jstl -->
	<dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>jstl</artifactId>
    	<version>1.2</version>
	</dependency>
	<!-- servlet-api -->
	<dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>servlet-api</artifactId>
    	<version>3.0-alpha-1</version>
	</dependency>
  	<!-- 数据库驱动依赖(oracle) -->
  	<!-- ojdbc14 -->
  	<dependency>
    	<groupId>com.oracle</groupId>
    	<artifactId>ojdbc14</artifactId>
    	<version>10.2.0.3.0</version>
	</dependency>
  	<!-- 定时器依赖(quartz) -->
  	<!-- core -->
  	<dependency>
    	<groupId>org.opensymphony.quartz</groupId>
    	<artifactId>quartz</artifactId>
    	<version>1.6.1</version>
	</dependency>
	<!-- quartz-oracle -->
	<dependency>
    	<groupId>org.opensymphony.quartz</groupId>
    	<artifactId>quartz-oracle</artifactId>
    	<version>1.6.1</version>
	</dependency>
  	<!-- 条形码依赖(jbarcode) -->
  	<dependency>
		<groupId>com.jbarcode</groupId>
		<artifactId>jbarcode</artifactId>
		<version>0.2.8</version>
	</dependency>
  	<!-- 宜信系统对接接口依赖(sia) -->
  	<dependency>
		<groupId>com.creditease.sia</groupId>
		<artifactId>sia-client</artifactId>
		<version>3.1.13</version>
	</dependency>
	<dependency>
		<groupId>org.mongodb</groupId>
		<artifactId>mongo-java-driver</artifactId>
		<version>2.5.3</version>
	</dependency>
	<dependency>
		<groupId>org.rabbitmq.client</groupId>
		<artifactId>rabbitmq-client</artifactId>
		<version>3.3.3</version>
	</dependency>
  	<!-- 日志管理依赖(log4j) -->
  	<dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.17</version>
	</dependency>
  	<!-- 解析json格式数据依赖(fastjson) -->
  	<dependency>
    	<groupId>com.alibaba</groupId>
    	<artifactId>fastjson</artifactId>
    	<version>1.2.8</version>
	</dependency>
  	<!-- 解析xml格式文件依赖(dom4j) -->
  	<!-- core -->
  	<dependency>
    	<groupId>dom4j</groupId>
    	<artifactId>dom4j-core</artifactId>
    	<version>1.4-dev-8</version>
	</dependency>
	<!-- dom4j -->
	<dependency>
    	<groupId>dom4j</groupId>
    	<artifactId>dom4j</artifactId>
    	<version>1.4-dev-8</version>
	</dependency>
	<!-- 数据源依赖 -->
	<!-- dbcp -->
	<dependency>
    	<groupId>commons-dbcp</groupId>
    	<artifactId>commons-dbcp</artifactId>
    	<version>20030825.184428</version>
	</dependency>
	<!-- c3p0 -->
	<!-- core -->
	<dependency>
    	<groupId>c3p0</groupId>
    	<artifactId>c3p0</artifactId>
    	<version>0.9.1.2</version>
	</dependency>
	<!-- c3p0-oracle -->
	<dependency>
    	<groupId>c3p0</groupId>
    	<artifactId>c3p0-oracle-thin-extras</artifactId>
    	<version>0.9.0.2</version>
	</dependency>
	<!-- tomcat依赖 -->
	<!-- tomcat-dbcp -->
	<dependency>
    	<groupId>org.apache.tomcat</groupId>
    	<artifactId>tomcat-dbcp</artifactId>
    	<version>9.0.0.M4</version>
	</dependency>
	<!-- tomcat-util -->
	<dependency>
    	<groupId>org.apache.tomcat</groupId>
    	<artifactId>tomcat-util</artifactId>
    	<version>9.0.0.M4</version>
	</dependency>
	<!-- tomcat-servlet-api -->
	<dependency>
    	<groupId>org.apache.tomcat</groupId>
    	<artifactId>tomcat-servlet-api</artifactId>
    	<version>9.0.0.M4</version>
	</dependency>
	<!-- tomcat-jsp-api -->
	<dependency>
    	<groupId>org.apache.tomcat</groupId>
    	<artifactId>tomcat-jsp-api</artifactId>
    	<version>9.0.0.M4</version>
	</dependency>
	<!-- tomcat-jdbc -->
	<dependency>
    	<groupId>org.apache.tomcat</groupId>
    	<artifactId>tomcat-jdbc</artifactId>
    	<version>9.0.0.M4</version>
	</dependency>
	<!-- alibaba_druid数据源依赖 -->
	<dependency>
    	<groupId>com.alibaba</groupId>
    	<artifactId>druid</artifactId>
    	<version>1.0.18</version>
	</dependency>
	<!-- 配置数据源连接池属性时依赖 -->
	<dependency>
    	<groupId>commons-pool</groupId>
    	<artifactId>commons-pool</artifactId>
    	<version>1.6</version>
	</dependency>
	<!-- javaMail邮件操作依赖 -->
	<dependency>
    	<groupId>javax.mail</groupId>
    	<artifactId>mail</artifactId>
    	<version>1.5.0-b01</version>
	</dependency>
  </dependencies>
</project>

2.配置jdbc.properties

#orcle
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@(DESCRIPTION = (jdbcFAILOVER = yes)(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.20.14)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.20.12)(PORT = 1521)) (CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = cedb)))
username=cams2
password=cKse*)^(23
initialSize=10
maxActive=100
maxIdle=30
minIdle=10
maxWait=60000 
removeAbandoned=true
removeAbandonedTimeout=120
logAbandoned=true 
validationQuery=select 1 from dual
testOnBorrow=true
testOnReturn=true
defaultAutoCommit=false
timeBetweenEvictionRunsMillis=180000
minEvictableIdleTimeMillis=180000

#mysql
#driver=com.mysql.jdbc.Driver
#url=jdbc:mysql://localhost:3306/action
#username=cams2
#password=cKse*)^(23

3.配置log4j.properties

#rootLogger
log4j.rootLogger=DEBUG,CONSOLE,CAMS2_PH_DEBUG,CAMS2_PH_ERROR

#CONSOLE-log
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=CAMS_PH --> %d{yyyy-MM-dd HH:mm:ss} --> [%p] METHODLOCATION-->[%l] MESSAGES-->[%m%n]

#CAMS2_PH_DEBUG-log
log4j.appender.CAMS2_PH_DEBUG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CAMS2_PH_DEBUG.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.CAMS2_PH_DEBUG.File=CAMS2_PH_DEBUG.log
log4j.appender.CAMS2_PH_DEBUG.Threshold = DEBUG 
log4j.appender.CAMS2_PH_DEBUG.layout=org.apache.log4j.PatternLayout
log4j.appender.CAMS2_PH_DEBUG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} --> [%p] METHODLOCATION-->[%l] MESSAGES-->[%m%n]

#CAMS2_PH_ERROR-log
log4j.appender.CAMS2_PH_ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CAMS2_PH_ERROR.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.CAMS2_PH_ERROR.File=CAMS2_PH_ERROR.log
log4j.appender.CAMS2_PH_ERROR.Threshold = ERROR 
log4j.appender.CAMS2_PH_ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.CAMS2_PH_ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} --> [%p] METHODLOCATION-->[%l] MESSAGES-->[%m%n]

#mybatis-sql-log
log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.com.creditease.cams2.ph.mapper=TRACE

4.配置spring-mybatis.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:p="http://www.springframework.org/schema/p"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="    
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-4.0.xsd
   		http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 

	<!-- 启动注解,添加注解支持 -->
	<context:annotation-config/>
	<!-- 自动扫描web包 ,将带有注解的类纳入spring容器管理 -->  
    <context:component-scan base-package="com.creditease.cams2.ph"></context:component-scan> 
    
    <!-- 引入jdbc配置文件 -->  
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath*:/db.properties</value>  
                <value>classpath*:/config.properties</value>  
            </list>  
        </property>  
    </bean>  
    
    <!--配置数据源(方式二_通过JNDI获得数据源的引用)		
	<bean id="dataSource2" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="java:comp/env/jdbc/cams2_ph"/> 
	</bean>
	 -->
	 
	<!--配置数据源(方式三),使用C3P0数据源实现 -->
 	<bean id="dataSource3" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  		<!-- 指定连接数据库的驱动 -->
  		<!-- 指定连接数据库的URL -->
  		<!-- 指定连接数据库的用户名 -->
  		<!-- 指定连接数据库的密码 -->
  		<!-- 指定连接数据库连接池的最大连接数 -->
  		<!-- 指定连接数据库连接池的最小连接数 -->
  		<!-- 指定连接数据库连接池的初始化连接数 -->
  		<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
  		<!-- 连mysql 
  		<property name="driverClass" value="com.mysql.jdbc.Driver"/>
  		<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/auction"/>
  		<property name="user" value="root"/>
  		<property name="password" value="32147"/>
  		<property name="maxPoolSize" value="40"/>
  		<property name="minPoolSize" value="1"/>
  		<property name="initialPoolSize" value="1"/>
  		<property name="maxIdleTime" value="20"/>
  		-->
  
  		<!--连MS-SQL
  		<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"></property> 
  		<property name="url" value="jdbc:jtds:sqlserver://10.11.68.28:1433;DatabaseName=txDB"></property>
  		<property name="username" value="sa"></property> 
  		<property name="password" value="Wang.Jun2009"></property>
 		--> 
 
  		<!-- 连 Oracle
  		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
  		<property name="url" value="jdbc:oracle:thin:@10.12.3.106:1521:orcl"></property>
  		<property name="username" value="pms"></property>
  		<property name="password" value="zerobugpms"></property>
  		<property name="maxActive" value="100"></property>
  		<property name="maxIdle" value="30"></property>
  		<property name="maxWait" value="500"></property>
  		<property name="defaultAutoCommit" value="true"></property>
  		-->
 	</bean>
 
 	<!-- 配置数据源(方式四),使用dbcp数据源实现  -->
 	<bean id="dataSource4" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">              
 		<!--  连接池启动时的初始值 
		<property name="initialSize" value="${initialSize}" />-->
		<!--  连接池的最大值 
		<property name="maxActive" value="${maxActive}" /> -->
		<!--  最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止
		<property name="maxIdle" value="${maxIdle}" /> -->
		<!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 
		<property name="minIdle" value="${minIdle}" />-->
		<!-- 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 
		<property name="maxWait" value="${maxWait}" />-->
		<!-- 是否自动回收超时连接 
		<property name="removeAbandoned" value="${removeAbandoned}" />-->
		<!-- 超时时间(以秒数为单位) 
		<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />-->
		<!-- 连接被泄露时是否打印
		<property name="logAbandoned" value="${logAbandoned}" /> -->
		<!-- 用来验证从连接池取出的连接 
		<property name="validationQuery" value="${validationQuery}" />-->
		<!-- 指明是否在从池中取出连接前进行检验
		<property name="testOnBorrow" value="${testOnBorrow}" /> -->
		<!-- 指明是否在归还到池中前进行检验
		<property name="testOnReturn" value="${testOnReturn}" /> -->        
 	</bean>  
 
	<!-- 配置数据源(方式五),使用springjdbc数据源实现  
 	<bean id="dataSource5" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		p:driverClassName="${DBDriver}" 
		p:url="${DBUrl}"
		p:username="${userName}" 
		p:password="${password}" /> 
 	-->
 	
    <!-- dataSource 配置方式一 -->  
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">  
        <!-- 基本属性 url、user、password -->  
        <property name="url" value="${url}" />  
        <property name="username" value="${username}" />  
        <property name="password" value="${password}" />  
  		<property name="driverClassName" value="${driver}"/>
        <!-- 配置初始化大小、最小、最大 -->  
        <property name="initialSize" value="${initialSize}" />  
        <property name="minIdle" value="${minIdle}" />  
        <property name="maxIdle" value="${maxIdle}" />  
        <property name="maxActive" value="${maxActive}" />  
        <!-- 配置获取连接等待超时的时间 -->  
        <property name="maxWait" value="${maxWait}" />  
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->  
        <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />  
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->  
        <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" /> 
        <!--  
        <property name="testWhileIdle" value="${testWhileIdle}" /> --> 
        <!-- 是否自动回收超时连接 -->
		<property name="removeAbandoned" value="${removeAbandoned}" />
		<!-- 超时时间(以秒数为单位) -->
		<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
		<!-- 连接被泄露时是否打印 -->
		<property name="logAbandoned" value="${logAbandoned}" />
		<!-- 用来验证从连接池取出的连接 -->
		<property name="validationQuery" value="${validationQuery}" />
		<!-- 指明是否在从池中取出连接前进行检验 -->
		<property name="testOnBorrow" value="${testOnBorrow}" />
		<!-- 指明是否在归还到池中前进行检验 -->
		<property name="testOnReturn" value="${testOnReturn}" />
    </bean>  
    
    <!-- 配置mybatis分页通用类 -->
	<bean id="paginationInterceptor" class="com.creditease.cams2.ph.util.intercepter.PageInterceptor"></bean> 
    
    <!-- mybatis文件配置,扫描所有mapper文件 -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
    	<property name="dataSource" ref="dataSource" />
    	<property name="mapperLocations" value="classpath:com/creditease/cams2/ph/mapper/*.xml"></property>
		<property name="typeAliasesPackage" value="com.creditease.cams2.ph.model" />
		<property name="plugins">  
            <ref bean="paginationInterceptor"/>  
        </property>
    </bean>
    	
    <!-- spring与mybatis整合配置,扫描所有mapper -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    	<property name="basePackage" value="com.creditease.cams2.ph.mapper" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean> 
  
    <!-- 对dataSource 数据源进行事务管理 -->  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
    	<property name="dataSource" ref="dataSource" />
    </bean>
  
    <!-- 启用对事务注解的支持
    <tx:annotation-driven transaction-manager="transactionManager" />  
  	-->
  	<!-- 声明方式配置事物 -->
	<!-- 配置事务传播特性 -->
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*" propagation="REQUIRED" read-only="false" />
		</tx:attributes>
	</tx:advice>
	<!-- 配置参与事务的类 -->
	<aop:config>
		<aop:pointcut id="transactionPointcut" expression="execution(* com.creditease.cams2.ph.service.*.*(..))" />
		<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
	</aop:config>
	
	<!-- 定义JavaMailSenderImpl,它用于发送邮件 -->
 	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  		<!-- 指定发送邮件的SMTP服务器地址 -->
  		<property name="host" value="smtp.163.com"/>
  		<property name="javaMailProperties">
   			<props>
    			<prop key="mail.smtp.auth">true</prop>
    			<prop key="mail.smtp.timeout">25000</prop>
   			</props>
  		</property>
  		<!-- 指定登录邮箱的用户名、密码 -->
  		<property name="username" value="spring_test"/>
  		<property name="password" value="123abc"/>
 	</bean>
 	<!-- 定义SimpleMailMessage Bean,它代表了一份邮件 -->
 	<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage">
  		<property name="from" value="spring_test@163.com"/>
  		<!-- 指定邮件标题 -->
  		<property name="subject" value="****"/>
 	</bean>
</beans>

5.配置spring-mvc.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:p="http://www.springframework.org/schema/p"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="    
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-4.0.xsd
   		http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 
        
    <!-- 启用springmvc注解 -->
    <context:annotation-config />
    
    <mvc:annotation-driven >
    	<!-- 消息转换器(解决responsebody 中文乱码) -->
    	<mvc:message-converters register-defaults="true">
      		<bean class="org.springframework.http.converter.StringHttpMessageConverter">
        		<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
      		</bean>
    	</mvc:message-converters>
  	</mvc:annotation-driven>

    <!-- 设置使用注解的类所在的类包,加载包中的controller  注解扫描包 -->
    <context:component-scan base-package="com.creditease.cams2.ph.controller"></context:component-scan>

    <!-- 完成请求和注解POJO的映射 (功能等同于<context:annotation-config />)
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>  
	-->

    <!-- 视图分解器 -->  
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/jsp/"/>  
        <property name="suffix" value=".jsp"/>  
    </bean> 
    
    <!-- 上传文件的解析器 -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <property name="defaultEncoding" value="UTF-8"/>  
        <property name="maxUploadSize" value="10485760000"/>  
        <property name="maxInMemorySize" value="40960"/>  
    </bean>
     
</beans>

6.配置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" 
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
	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>cams_ph</display-name>
	<!-- 项目描述 -->
	<description>档案管理系统二期普惠端</description>
	
	<!-- 启用监听器,添加对spring框架的支持 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 指定监听器监听地址 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<!-- 如果没有写value值,则默认加载applicationContext.xml文件 -->
		<param-value>classpath*:applicationContext.xml</param-value>
	</context-param>
	
	<!-- 启用拦截器,添加对struts2的支持 
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	-->
	<!-- 指定对哪些文件进行拦截 
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	-->
	<!-- 通过servlet映射添加对springmvc框架的支持 -->
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
		<!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如springmvc-servlet.xml -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath*:springmvc-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	<!-- filter(过滤字符编码,以防中文乱码等问题) -->
	<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>
	
	<!-- filter(用于拦截不能通过浏览器地址栏访问系统其它资源) 
	<filter>
		<filter-name>loginFilter</filter-name>
		<filter-class>com.creditease.cams2.ph.util.filter.LoginFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>loginFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	-->
	<!-- listener(监听session的生命周期),确保单点登录 
	<listener>
		<listener-class>com.creditease.cams2.ph.util.listener.SessionLifecycleListener</listener-class>
	</listener>
	-->
	<!-- servlet(quartz定时处理,随着项目的启动而启动) -->
	<servlet>
		<servlet-name>QuartzServlet</servlet-name>
		<servlet-class>com.creditease.cams2.ph.util.servlet.QuartzServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	
	<!-- 项目启动首页(欢迎页),此处指登录页 -->
	<welcome-file-list>
		<welcome-file>jsp/systemManage/loginManage/loginManage.jsp</welcome-file>
	</welcome-file-list>
	
	<!-- session过期时间,1=1min -->
	<session-config>
		<session-timeout>20</session-timeout>
	</session-config>
	
	<!-- 请求返回错误和异常的跳转错误页 -->
	<error-page>
		<!-- 禁止访问 -->
		<error-code>403</error-code>
		<location>/jsp/systemManage/exceptionManage/exceptionManage.jsp</location>
	</error-page>
	<error-page>
		<!-- 请求的资源不存在 -->
		<error-code>404</error-code>
		<location>/jsp/systemManage/exceptionManage/exceptionManage.jsp</location>
	</error-page>
	<error-page>
		<!-- 服务器错误返回 -->
		<error-code>500</error-code>
		<location>/jsp/systemManage/exceptionManage/exceptionManage.jsp</location>
	</error-page>
	<error-page>
		<!-- 请求返回异常 -->
		<exception-type>java.lang.Exception</exception-type>
		<location>/jsp/systemManage/exceptionManage/exceptionManage.jsp</location>
	</error-page>
	
	<!-- 配置数据库连接池(jndi方式) -->
	<resource-ref>   
    	<description>JNDI JDBC DataSource</description>   
    	<res-ref-name>jdbc/cams2_ph</res-ref-name>   
    	<res-type>javax.sql.DataSource</res-type>   
    	<res-auth>Container</res-auth>   
	</resource-ref>
</web-app>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值