SpringMVC+mybatis+maven整合
一、项目架构效果图
二、项目源码
1.pom.xml
<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>cn.gszhang</groupId>
<artifactId>gszhang</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- 主要依赖库的版本定义 -->
<spring.version>3.2.4.RELEASE</spring.version>
<mybatis.version>3.2.2</mybatis.version>
<activemq.version>5.5.1</activemq.version>
<quartz.version>1.8.4</quartz.version>
<lucene.version>5.3.1</lucene.version>
<servlet.version>2.5</servlet.version>
<slf4j.version>1.7.5</slf4j.version>
<logback.version>1.0.13</logback.version>
<jsp.version>2.1</jsp.version>
<jdk.version>1.7</jdk.version>
</properties>
<!-- LOGGING begin -->
<dependencies>
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- logback-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- LOGGING end -->
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewrite</artifactId>
<version>2.5.2</version>
</dependency>
<!-- XML begin -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-ri</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- XML end -->
<!-- EXCEL begin -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- EXCEL end -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.2</version>
</dependency>
<!-- GENERAL UTILS begin -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.2</version>
</dependency>
<!-- SPRING basic begin -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- jms begin -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.5.1.MF</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>kahadb</artifactId>
<version>${activemq.version}</version>
</dependency>
<!-- jms end -->
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.RC2</version>
</dependency>
<!--bouncycastle-->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bouncycastle</artifactId>
<version>1.1</version>
</dependency>
<!-- email/scheduler/freemarker -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- SPRING basic end -->
<!-- AOP begin-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.9</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
</dependency>
<!-- AOP end -->
<!-- PERSISTENCE begin -->
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<!-- spring orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- optional datasource pool -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2.1</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.4</version>
</dependency>
<!-- PERSISTENCE end -->
<!-- spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
</dependency>
<!-- timer-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<!-- 添加lucene支持 -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-smartcn</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- compiler插件, 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!-- clean插件 -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<!-- war打包插件, 设定war包名称不带版本号 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
<!-- jar打包相关插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<!-- resource插件 -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
<!-- dependency相关插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
</plugin>
<!-- test插件, 仅测试名称为*Test的类-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>gszhang</finalName>
</build>
</project>
2、logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration scan="true" scanPeriod="5 seconds">
<property name="log.base" value="/logs/gszhang/gszhang"/>
<!-- Console stdout -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender>
<!--#INFO Appender (Store info message, rolling with daily,The default log for 30 days) -->
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.base}.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-4relative [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender>
<!--#ERROR Appender (Store error message, rolling with daily,The default log for 30 days) -->
<appender name="ErrorRollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.base}-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-4relative [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender>
<!--#TraceFile Appender (Store debug message, rolling with 100M, 10 files, threshold is OFF)-->
<appender name="TraceRollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base}-trace.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${log.base}-trace%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>100MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%date %-4relative [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender>
<appender name="RecoredLoginErrorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base}-loginError.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${log.base}-loginError%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>100MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%date %-4relative [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender>
<!--Application log is appended to the RollingFile,The default level is INFO-->
<logger name="cn.gszhang">
<appender-ref ref="RollingFile"/>
</logger>
<!--Application log is appended to the ErrorRollingFile,The default level is ERROR-->
<logger name="cn.gszhang">
<appender-ref ref="ErrorRollingFile"/>
</logger>
<logger name="com.google.code.yanf4j" level="warn">
<appender-ref ref="RollingFile"/>
</logger>
<logger name="org.apache.activemq" level="warn">
<appender-ref ref="RollingFile"/>
</logger>
<!--Application log is appended to the Console and TraceRollingFile,The default level is ERROR-->
<!-- <root level="DEBUG"> -->
<root level="DEBUG">
<appender-ref ref="stdout"/>
<appender-ref ref="TraceRollingFile"/>
</root>
</configuration>
3.db.properties
#MySQL
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.host=192.168.1.198
jdbc.databaseName=gszhang
jdbc.url=jdbc:mysql://${jdbc.host}:3306/${jdbc.databaseName}?useUnicode=true&characterEncoding=utf8
#### 数据库的用户名
jdbc.username=root
#### 数据库 密码
jdbc.password=123456
#### 连接池中保留的最小连接数
minPoolSize=5
#### 连接池中保留的最大连接数。Default: 15
maxPoolSize=30
#### 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3
initialPoolSize=10
#### 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0
maxIdleTime=60
#### 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3
acquireIncrement=5
#### JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的 statements属于单个connection而不是整个连接池。
#### 所以设置这个参数需要考虑到多方面 的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0
maxStatements=0
#### 每60秒检查所有连接池中的空闲连接。Default: 0
idleConnectionTestPeriod=60
#### 定义在从数据库获取新连接失败后重复尝试的次数。Default: 30
acquireRetryAttempts=30
#### 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,
#### 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。Default: false
breakAfterAcquireFailure=true
#### 因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
#### 等方法来提升连接测试的性能。Default: false
testConnectionOnCheckout=false
4、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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>gszhang</display-name>
<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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<!-- <filter>
<filter-name>jcaptchaFilter</filter-name>
<filter-class>cn.gszhang.common.base.security.jcatpcha.JCaptchaFilter</filter-class>
<init-param>
<param-name>failureUrl</param-name>
<param-value>/security/login</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jcaptchaFilter</filter-name>
<url-pattern>/security/jcaptcha.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>jcaptchaFilter</filter-name>
<url-pattern>/security/doLogin</url-pattern>
</filter-mapping>
<filter>
<filter-name>jcaptchaFilterRetrivPwd</filter-name>
<filter-class>cn.gszhang.common.base.security.jcatpcha.JCaptchaFilter</filter-class>
<init-param>
<param-name>failureUrl</param-name>
<param-value>/security/forgetpwd</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jcaptchaFilterRetrivPwd</filter-name>
<url-pattern>/security/pwdIocn_11.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>jcaptchaFilterRetrivPwd</filter-name>
<url-pattern>/security/stepone</url-pattern>
</filter-mapping> -->
<filter>
<filter-name>imageFilter</filter-name>
<filter-class>cn.gszhang.common.base.filter.ImageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>imageFilter</filter-name>
<url-pattern>/security/doLogin</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>RandomCode</servlet-name>
<servlet-class>cn.gszhang.common.base.utils.RandomCode</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RandomCode</servlet-name>
<url-pattern>/randomCode</url-pattern>
</servlet-mapping>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping> -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>initApplicationScopeCreatorsAtStartup</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>maxWaitAfterWrite</param-name>
<param-value>1000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>warn</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>org.directwebremoting.extend.Remoter</param-name>
<param-value>cn.gszhang.common.DWRSessionService</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
5、mybatis-resources.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 全局启用或禁用缓存 -->
<setting name="cacheEnabled" value="false"/>
<!-- 全局禁用延迟加载 -->
<setting name="lazyLoadingEnabled" value="false"/>
<!-- 配合延迟加载使用 -->
<setting name="aggressiveLazyLoading" value="true"/>
<!-- 执行器重用语句和批量更新 -->
<setting name="defaultExecutorType" value="BATCH"/>
</settings>
<typeAliases>
<typeAlias type="cn.gszhang.project.system.domain.SysUser" alias="SysUser"/>
<typeAlias type="cn.gszhang.project.system.domain.SysRole" alias="SysRole"/>
<typeAlias type="cn.gszhang.project.system.domain.Menu" alias="Menu"/>
<typeAlias type="cn.gszhang.project.system.domain.Resource" alias="Resource"/>
<typeAlias type="cn.gszhang.project.system.domain.Permission" alias="Permission"/>
<typeAlias type="cn.gszhang.common.base.support.PageBean" alias="PageBean"/>
</typeAliases>
</configuration>
6、spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="classpath*:applicationContext-dao.xml"/>
<import resource="classpath*:applicationContext-redis.xml"/>
<import resource="classpath*:applicationContext-jms.xml"/>
<import resource="classpath*:applicationContext-schedule.xml"/>
<mvc:default-servlet-handler/>
<!--Jackson-->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- <mvc:resources location="/image/" mapping="/image/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/js/" mapping="/js/**"/> -->
<!--登录拦截器-->
<mvc:interceptors>
<mvc:interceptor>
<!-- 需拦截的地址 -->
<!-- 一级目录 -->
<mvc:mapping path="/home/*" />
<!-- 需排除拦截的地址 -->
<mvc:exclude-mapping path="/security/login,/security/doLogin"/>
<bean class="cn.gszhang.common.base.interceptor.LoginInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
7、applicationContext-schedule.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true">
<description>定时周期任务配置执行文件</description>
<bean id="exportXMLThread" class="cn.gszhang.common.test.Test"/>
<bean id="exportXMLJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exportXMLThread"/>
<property name="targetMethod" value="exportXML"/>
<property name="concurrent" value="false"/>
</bean>
<bean id="exportXMLTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="exportXMLJob"/>
<!--测试时配置1分钟执行一次-->
<property name="cronExpression" value="0 0/1 * * * ?"/>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="exportXMLTrigger"/>
</list>
</property>
</bean>
</beans>
8、applicationContext-redis.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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:password="" p:pool-config-ref="poolConfig"/>
<bean id="stringSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<!-- 开启事务,可以通过transcational注解控制 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer" ref="stringSerializer" />
<property name="enableTransactionSupport" value="true" />
</bean>
</beans>
9、applicationContext-jms.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- ActiveMQ 连接工厂 -->
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="${jms.broker_url}"/>
<property name="userName" value="${jms.userName}"/>
<property name="password" value="${jms.password}"/>
</bean>
<!-- Spring Caching 连接工厂 -->
<bean id="cachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="connectionFactory"/>
<property name="sessionCacheSize" value="${jms.sessionCacheSize}"/>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="cachingConnectionFactory"/>
<property name="receiveTimeout" value="10000"/>
</bean>
<bean id="autoruleQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="q.autoruleQueue"/>
</bean>
<bean id="sendAutoRuleCmdProducer" class="cn.gszhang.common.base.jms.producor.NotifyMessageProducer">
<property name="destinationQueue" ref="autoruleQueue"/>
<property name="jmsTemplate" ref="jmsTemplate"/>
</bean>
<!-- 单点登录的生产者和消费者 -->
<!-- 生产者 -->
<bean id="singleLoginTopic" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="t.ssPortalSingleLogin"/>
</bean>
<bean id="singleLoginTopicProducer" class="cn.gszhang.common.base.jms.producor.NotifyMessageProducer" autowire="byName">
<property name="destinationQueue" ref="singleLoginTopic"/>
<property name="jmsTemplate" ref="jmsTemplate"/>
</bean>
<!-- 消费者 -->
<bean id="singleLoginListener" class="cn.gszhang.common.base.jms.JMSSingleLoginListener" scope="singleton">
</bean>
<bean id="SingleLoginQueueContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destination" ref="singleLoginTopic"/>
<property name="messageListener" ref="singleLoginListener"/>
<property name="concurrentConsumers" value="1"/>
</bean>
<!-- 单点登录的生产者和消费者 end-->
</beans>
10、applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--<bean class="com.huawei.m2m.base.config.M2MPropertyDecryptPropertyConfigure">-->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="order" value="1"/>
<property name="locations">
<list>
<!--数据库配置-->
<value>classpath*:db.properties</value>
</list>
</property>
</bean>
<context:component-scan base-package="cn.gszhang"/>
<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<!-- <context:component-scan base-package="cn.gszhang.project.orm.mybatis"/> -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${jdbc.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${jdbc.url}</value>
</property>
<property name="user">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="minPoolSize">
<value>${minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${maxPoolSize}</value>
</property>
<property name="initialPoolSize">
<value>${initialPoolSize}</value>
</property>
<property name="maxIdleTime">
<value>${maxIdleTime}</value>
</property>
<property name="acquireIncrement">
<value>${acquireIncrement}</value>
</property>
<property name="maxStatements">
<value>${maxStatements}</value>
</property>
<property name="idleConnectionTestPeriod">
<value>${idleConnectionTestPeriod}</value>
</property>
<property name="acquireRetryAttempts">
<value>${acquireRetryAttempts}</value>
</property>
<property name="breakAfterAcquireFailure">
<value>${breakAfterAcquireFailure}</value>
</property>
<property name="testConnectionOnCheckout">
<value>${testConnectionOnCheckout}</value>
</property>
</bean>
<!-- mybitas 配置 sqlSessionFactory -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-resources.xml"></property>
<property name="mapperLocations">
<list>
<value>classpath:cn/gszhang/project/*/mapper/**Mapper.xml</value>
</list>
</property>
</bean>
<!--jdbcTemplate define -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
<!-- 事务定义 start -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--默认事务声明-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="NESTED"/>
<tx:method name="update*" propagation="NESTED"/>
<tx:method name="del*" propagation="NESTED"/>
<tx:method name="add*" propagation="NESTED"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 事务定义 end -->
<!-- 告诉事务管理器 那些包以及那些类下需要Spring 去管理事务(一定是在SERVICE层上处理事务) -->
<aop:config>
<aop:pointcut expression="execution(* cn.gszhang.project.*.service.*.*(..))" id="perform"/>
<aop:advisor pointcut-ref="perform" advice-ref="txAdvice"/>
</aop:config>
<!-- 加载数据库配置文件 -->
<bean class="cn.gszhang.common.base.holder.SysparamPropertiesHolder">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="order" value="2"/>
</bean>
<bean id="systemParams" class="cn.gszhang.common.base.utils.SystemParams">
<property name="fileServerIp" value="${fileServerIp}"/>
<property name="fileServerPort" value="${fileServerPort}"/>
</bean>
</beans>