Spring+SpringMVC+Mybatis+MAVEN+Eclipse+项目完整环境搭建

1、新建一个Maven项目,创建父项目。

 

2、创建子项目模块

3、创建javaWeb项目

4、创建后的项目目录结构

 

5、Maven文件配置

  

  • parent父项目pom.xml文件配置

 

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->
  <modelVersion>4.0.0</modelVersion>
  <!--项目的全球唯一标识符,通常使用全限定的包名区分该项目和其他项目。并且构建时生成的路径也是由此生成, 如com.mycompany.app生成的相对路径为:/com/mycompany/app-->   
  <groupId>com.lovo</groupId>
  <!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;
               在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。--> 
  <artifactId>parent</artifactId>
  <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->
  <version>0.0.1-SNAPSHOT</version>
  <!--项目产生的构件类型,例如jar、war、ear、pom。插件可以创建他们自己的构件类型,所以前面列的不是全部构件类型-->
  <packaging>pom</packaging>
  <!--项目的名称, Maven产生的文档用-->
  <name>${project.artifactId}</name>
  <!-- 描述 -->
  <description>Spring SpringMVC Mybatis Project</description>
  <!-- compiler插件能解决: 
        1:maven 2.1默认用jdk 1.3来编译,maven 3 貌似是用jdk 1.5,如果项目用的jdk 1.6也会有问题,compiler插件可以指定JDK版本为1.6。 
        2:windows默认使用GBK编码,java项目经常编码为utf8,也需要在compiler插件中指出,否则中文乱码可能会出现编译错误。 -->
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- 设置JDK版本1.8 -->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
  </build>
  <!--模块(有时称作子项目) 被构建成项目的一部分。列出的每个模块元素是指向该模块的目录的相对路径-->
  <modules>
      <module>soncore</module>
      <module>sonstore</module>
      <module>sonutils</module>
    <module>admin</module>
  </modules>
  <properties>
         <!-- Maven 编译使用的字符集编码 -->
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       <!-- jar包版本 -->
       <slf4j.version>1.7.12</slf4j.version>
  </properties>
  <dependencies>
      <!-- slf4j日志包 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
  </dependencies>
</project>
  • Soncore项目pom.xml文件配置
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->
  <modelVersion>4.0.0</modelVersion>
  <!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。-->
  <parent>
      <!--被继承的父项目的全球唯一标识符-->
    <groupId>com.lovo</groupId>
    <!--被继承的父项目的构件标识符--> 
    <artifactId>parent</artifactId>
    <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;
        在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。-->
  <artifactId>soncore</artifactId>
  <!--项目的名称, Maven产生的文档用-->
  <name>${project.artifactId}</name>
  <!--被继承的父项目的版本-->
  <version>${project.parent.version}</version>
  <!-- 描述 -->
  <description>parent project soncore code </description>
      <properties>
          <!-- Maven 编译使用的字符集编码 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- jar包版本 -->
        <spring.version>4.2.6.RELEASE</spring.version>
        <aspectj.version>1.8.9</aspectj.version>
        <mybatis.version>3.4.0</mybatis.version>
        <mybatis-spring.version>1.3.0</mybatis-spring.version>
        <mysql.version>5.1.38</mysql.version>
        <fastjson.version>1.2.12</fastjson.version>
        <base64.version>2.3.9</base64.version>
    </properties>
    <!--构建项目需要的信息-->
    <build>
        <!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。-->
        <!-- 加上这个可以保证maven打包是把这些资源文件都打到war包中 -->
        <resources>
            <!--这个元素描述了项目相关或测试相关的所有资源路径-->
            <resource>
                <!--描述存放资源的目录,该路径相对POM路径--> 
                <directory>src/main/java</directory>
                <!--包含的模式列表,例如**/*.xml.-->
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <!--是否使用参数值代替参数名。参数值取自properties元素或者文件里配置的属性,文件在filters元素里列出。-->
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    <dependencies>
        <!-- 必须的不解释,面向切面编程jar包 -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <!-- Spring相关包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </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-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.19</version>
        </dependency>
        <!-- mybatis相关包 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis-spring.version}</version>
        </dependency>
        <!-- mysql相关包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- fastjson相关包 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <!-- Base64相关包 -->
        <dependency>
            <groupId>net.iharder</groupId>
            <artifactId>base64</artifactId>
            <version>${base64.version}</version>
        </dependency>
    </dependencies>
</project>
  • Sonutils项目pom.xml文件配置
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->
  <modelVersion>4.0.0</modelVersion>
  <!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。-->
  <parent>
    <!--被继承的父项目的全球唯一标识符--> 
    <groupId>com.lovo</groupId>
      <!--被继承的父项目的构件标识符--> 
    <artifactId>parent</artifactId>
    <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->   
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;
        在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。-->   
  <artifactId>sonutils</artifactId>
  <!--项目的名称, Maven产生的文档用-->
  <name>${project.artifactId}</name>
  <!-- 描述 -->
  <description>parent project sontils code</description>
  <!--被继承的父项目的版本-->
  <version>${project.parent.version}</version>
  <!-- Maven 编译使用的字符集编码 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <!--项目引入插件所需要的额外依赖-->    
    <dependencies>
        <!-- 依赖ssmcore -->
        <dependency>
            <groupId>com.lovo</groupId>
            <artifactId>soncore</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <!-- HttpComponents 也就是以前的httpclient项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端/服务器编程工具包,并且它支持 HTTP 协议最新的版本和建议 -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
    </dependencies>
</project>
  • Sonstore项目pom.xml文件配置
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->
    <modelVersion>4.0.0</modelVersion>
    <!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。-->
    <parent>
          <!--被继承的父项目的全球唯一标识符--> 
        <groupId>com.lovo</groupId>
        <!--被继承的父项目的构件标识符-->
        <artifactId>parent</artifactId>
        <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号--> 
        <version>0.0.1-SNAPSHOT</version>
     </parent>
      <!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;
         在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。-->     
     <artifactId>sonstore</artifactId>
     <!--项目的名称, Maven产生的文档用-->
     <name>soncore</name>
     <!-- 描述 -->
     <description>parent project sonstore code</description>
     <!--项目主页的URL, Maven产生的文档用-->
    <url>http://maven.apache.org</url>
    <!-- Maven 编译使用的字符集编码 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <!--项目引入插件所需要的额外依赖-->
    <dependencies>
        <!-- 依赖ssmutils -->
        <dependency>
            <groupId>com.lovo</groupId>
            <artifactId>sonutils</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
    </dependencies>
</project>
  • Admin项目(WEB)pom.xml文件配置
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->
  <modelVersion>4.0.0</modelVersion>
  <!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。-->
  <parent>
      <!--被继承的父项目的全球唯一标识符-->
    <groupId>com.lovo</groupId>
    <!--被继承的父项目的构件标识符-->
    <artifactId>parent</artifactId>
    <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;
        在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。-->
  <artifactId>admin</artifactId>
  <!--项目产生的构件类型,例如jar、war、ear、pom。插件可以创建他们自己的构件类型,所以前面列的不是全部构件类型-->
  <packaging>war</packaging>
  <name>admin Webapp</name>
  <url>http://maven.apache.org</url>
  
      <build>
       <!-- maven打包后的项目名 --> 
        <finalName>admin</finalName>
        <!-- 加上这个可以保证maven打包是把这些资源文件都打到war包中 -->  
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
    <properties>
        <!-- jar包版本 -->
        <servlet.version>4.0.0-b01</servlet.version>
        <druid.version>1.0.20</druid.version>
        <commons-io.version>2.4</commons-io.version>
        <commons-fileupload.version>1.3.1</commons-fileupload.version>
        <jackson.version>2.7.4</jackson.version>
        <ehcache.version>2.10.2</ehcache.version>
        <validator.version>5.2.3.Final</validator.version>
        <ehcache.jgroupsreplication.version>1.7</ehcache.jgroupsreplication.version>
    </properties>
     <!-- 项目基础依赖包配置 -->
    <dependencies>
        <!-- 系统其他模块 -->
        <dependency>
            <groupId>com.lovo</groupId>
            <artifactId>soncore</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>com.lovo</groupId>
            <artifactId>sonutils</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>com.lovo</groupId>
            <artifactId>sonstore</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <!-- servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
        </dependency>
        <!-- druid相关包 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>
        <!-- commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>
        <!-- commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>${commons-fileupload.version}</version>
        </dependency>
        <!-- ehcache -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>${ehcache.version}</version>
        </dependency>
        <!-- jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <!-- 校验 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${validator.version}</version>
        </dependency>
        <!-- 集群 -->
        <!--<dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-jgroupsreplication</artifactId>
            <version>${ehcache.jgroupsreplication.version}</version>
        </dependency>
        -->
    </dependencies>
</project>

6、Spring SpringMVC Mybatis框架文件配置

  • applicationContext.xml文件配置
<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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:cache="http://www.springframework.org/schema/cache" xmlns:c="http://www.springframework.org/schema/c"
    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/aop 
                        http://www.springframework.org/schema/aop/spring-aop.xsd 
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx.xsd 
                        http://www.springframework.org/schema/cache 
                        http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
                        
                        
    <!-- 配置需要交给spring扫描管理的包,一般是包括整个项目的java文件的父包(由context提供) -->
    <context:component-scan base-package="org.system" />
    <!-- 属性文件读入,用于加密数据库配置文件 -->
    <bean id="propertyConfigurer" class="org.core.encrypt.DBConfigurer">
        <property name="locations">
            <list>
                <value>classpath:conf.properties</value>
            </list>
        </property>
    </bean>
    <!-- 配置需要交给spring扫描管理的文件,一般是项目的配置文件(由context提供) -->
    <context:property-placeholder location="classpath:conf.properties" />
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  
        destroy-method="close">  
        <property name="url" value="${url}" /> 
        <!-- 数据库连接用户名 --> 
        <property name="username" value="${username}" />  
        <!-- 数据库连接密码 --> 
        <property name="password" value="${password}" />  
        <!-- 初始化连接大小 -->  
        <property name="initialSize" value="2"></property>  
        <!-- 连接池最大数量 -->  
        <property name="maxActive" value="20"></property>  
        <!-- 连接池最大空闲 ,对象池中对象最大个数-->  
        <!-- <property name="maxIdle" value="60000"></property>   -->
        <!-- 连接池最小空闲,对象池中对象最小个数 -->  
        <property name="minIdle" value="2"></property>  
        <!-- 获取连接最大等待时间,单位为 ms, 超过时间会丟出错误信息 -->  
        <property name="maxWait" value="60000"></property>  
        <!-- 每多少毫秒检测空闲连接超过10分钟的连接; 失效检查线程运行时间间隔,如果小于等于0,不会启动检查线程,默认-1-->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 连接池中连接,在时间段内一直空闲, 被逐出连接池的时间 (默认为30分钟,可以适当做调整,需要和后端服务端的策略配置相关) ; 
                  大于0 ,进行连接空闲时间判断,或为0,对空闲的连接不进行验证;默认30分钟  -->
        <property name="minEvictableIdleTimeMillis" value="25200000" />
        <!-- 超过时间限制,回收没有用(废弃)的连接(默认为 300秒,调整为180); -->
        <property name="removeAbandonedTimeout" value="1800" />
    </bean>  
      <!-- 配置sqlSessionFactory(由mybatis-spring.jar提供支持) -->
    <bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 配置数据源 -->
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:configuration.xml" />
        <!-- 配置拦截器用于Mybatis分页和总数查询,只实现Mysql -->
        <property name="plugins" ref="PaginationInterceptor" />
    </bean>
    <!-- Mybatis分页拦截器 -->
    <bean name="PaginationInterceptor" class="org.core.intercept.PaginationInterceptor" />
    <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="org.system.mapper..*" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>
    <!-- 支持缓存注解 -->
    <cache:annotation-driven cache-manager="cacheManager" />
    <!-- Spring提供的基于的Ehcache实现的缓存管理器 -->
    <bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml" />
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcacheManager" />
    </bean>
    <!-- 支持注解事务模式 -->
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />
    <!-- 事务管理 -->
    <bean name="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="insert*" propagation="REQUIRED" read-only="false" />
            <tx:method name="delete*" propagation="REQUIRED" read-only="false" />
            <tx:method name="update*" propagation="REQUIRED" read-only="false" />
            <tx:method name="get*" propagation="SUPPORTS" />
        </tx:attributes>
    </tx:advice>
    <!-- 配置该声明式事务规则用于的切入点 步骤: 1.配置切入点 2.应用该声明式事务规则 -->
    <aop:config proxy-target-class="true" expose-proxy="true">
        <!-- 配置切入点 -->
        <aop:pointcut id="transaction_pointcut"
            expression="execution(* org.system.service.impl..*.*(..))" />
        <!-- 应用该声明式事务规则 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="transaction_pointcut" />
    </aop:config>
    <!-- 异常拦截器 -->
    <bean id="exceptionHandler" class="org.system.exception.MyExceptionResolver" />
</beans>
  • conf.properties文件配置
#数据库连接
driver=com.mysql.jdbc.Driver
#本机连接
url=5BiJrAunhbp4C6R9HY+UQZca6/Y+XPBCNv95/EzYAmjeJzpWpDD3ac0D2WtX+4UbeHW7DCcv755VyGJfUylG1DZfbpB4tbaTpnYigXCccc9FefU
#数据库账号 密码
username=Y0Z2wmLw+BM=
password=Y0Z2wmLw+BM=

#文件服务器配置
#file.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC1FOh0jnud2NK+z2gemMYlVb36LsAOnEMs855NUR4OZd9k5kiWdmaifL8li6DaVyP/pMpnVdK1fymt2UzSejtswCDG
#file.account=admin
#file.password=123456
#开发环境
#file.url=
#云端环境
#file.url=
#HIS服务器配置
#his.publicKey=
#his.account=admin
#his.password=123456
#开发环境
#his.url=
#云端环境
#his.url=
#语音服务器配置
#phone.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC1FOh0jnud2NK+z2
#phone.account=admin
#phone.password=123456
#phone.url=

#微信服务器配置
#测试 
#wechat.url=
  • spring-mvc.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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: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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
                        
    <!-- 扫描要自动管理的包,使SpringMVC认为包下用了@Controller 注解的类是控制器 -->
    <context:component-scan base-package="org.system.controller" />
    <!-- 添加注解驱动,扩充了注解驱动,可以将请求参数绑定到控制器参数 -->
    <mvc:annotation-driven enable-matrix-variables="true" />
    <!-- 静态资源处理,静态资源文件路径设置 -->
    <mvc:resources location="/styles/" mapping="/styles/.**" />
    <mvc:resources location="/images/" mapping="/images/.**" />
    <mvc:resources location="/plugins/" mapping="/plugins/.**" />
    <mvc:resources location="/scripts/" mapping="/scripts/.**" />
    <mvc:resources location="/html/" mapping="/html/.**" />
    <mvc:resources location="/index.html" mapping="/index.html" />
     <!--避免IE执行AJAX时,返回JSON出现下载文件  -->
    <bean id="mappingJacksonHttpMessageConverter"  
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean> 
    <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->  
    <bean  
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 -->  
            </list>  
        </property>  
    </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" />    
        <!-- 启用是为了推迟文件解析,以便捕获文件大小异常 -->
        <property name="resolveLazily" value="true"/>
    </bean> 
    <!-- 定义跳转的文件的前后缀 ,视图模式配置-->  
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->  
        <property name="prefix" value="/" />  
        <property name="suffix" value=".html" />  
    </bean> 
    <!-- 校验拦截器 -->
    <bean id="validInterceptor" class="org.system.intercept.ValidInterceptor"></bean>
    <!-- 配置AOP切点 只拦截Controltroller -->
    <aop:config>
        <!--切入点 -->
        <aop:pointcut id="validPoint"
            expression="execution(public * org.system.controller.impl..*.*(..))" />
        <!--在该切入点使用自定义拦截器 -->
        <aop:advisor pointcut-ref="validPoint" advice-ref="validInterceptor" />
    </aop:config>
    <!-- 导入其他配置文件 -->
    <import resource="/org/system/config/*.xml" />
</beans>  
  • configuration.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL MAP Config 3.1//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <settings>
      <setting name="callSettersOnNulls" value="true"/>
  </settings>
</configuration>
  • log4j.properties文件配置
#定义根级别
log4j.rootLogger = ERROR,info,warn,error,stdout

#定义项目输出日志级别
log4j.logger.org.system = DEBUG
log4j.logger.org.core = INFO
log4j.logger.org.utils = INFO
log4j.logger.org.springframework.web.servlet.mvc = WARN

#控制台输出 生成阶段注释
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{MM-dd HH:mm:ss}-[%p] [%c{3}] %m%n

###info级别输出
#设置日志输出类型为每天产生一个日志文件
log4j.appender.info = org.apache.log4j.DailyRollingFileAppender
#指定输出目录  
log4j.appender.info.File = ${catalina.home}/logs/${webapp.root}/admin/info.log
#默认值是true,即将消息追加到指定文件中,false指将消息覆盖指定的文件内容。
log4j.appender.info.Append = true
#指定日志消息的输出最低级别,此处设置为INFO,当程序出现错误日志时也会输出到此日志文件中
log4j.appender.info.Threshold = INFO 
#设置输出端的布局类型为可以灵活地指定布局模式
log4j.appender.info.layout = org.apache.log4j.PatternLayout
#指定打印信息的具体格式
log4j.appender.info.layout.ConversionPattern = %-d{MM-dd HH:mm:ss}-[%p] [%c{3}] %m%n
#指定每天产生一个文件
log4j.appender.info.datePattern='.'yyyy-MM-dd
#定制过滤器 只过滤INFO级别
log4j.appender.info.filter.infoFilter = org.apache.log4j.varia.LevelRangeFilter
log4j.appender.info.filter.infoFilter.LevelMin=INFO
log4j.appender.info.filter.infoFilter.LevelMax=INFO

###warn级别输出
log4j.appender.warn = org.apache.log4j.DailyRollingFileAppender
log4j.appender.warn.File = ${catalina.home}/logs/${webapp.root}/admin/warn.log
log4j.appender.warn.Append = true
log4j.appender.warn.Threshold = warn 
log4j.appender.warn.layout = org.apache.log4j.PatternLayout
log4j.appender.warn.layout.ConversionPattern = %-d{MM-dd HH:mm:ss}-[%p] [%c{3}] %m%n
log4j.appender.warn.datePattern='.'yyyy-MM-dd
#定制过滤器 只过滤warn级别
log4j.appender.warn.filter.warnFilter = org.apache.log4j.varia.LevelRangeFilter
log4j.appender.warn.filter.warnFilter.LevelMin=WARN
log4j.appender.warn.filter.warnFilter.LevelMax=WARN

###error级别输出
log4j.appender.error = org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File = ${catalina.home}/logs/${webapp.root}/admin/error.log
log4j.appender.error.Append = true
log4j.appender.error.Threshold = ERROR 
log4j.appender.error.layout = org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern = %-d{MM-dd HH:mm:ss}-[%p] [%c{3}] %m%n
log4j.appender.error.datePattern='.'yyyy-MM-dd
#定制过滤器 只过滤ERROR级别
log4j.appender.error.filter.errorFilter=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.error.filter.errorFilter.LevelMin=ERROR
log4j.appender.error.filter.errorFilter.LevelMax=ERROR
  • ehcache.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
    updateCheck="false">

<!--timeToIdleSeconds 当缓存闲置n秒后销毁 --> 
<!--timeToLiveSeconds 当缓存存活n秒后销毁 --> 
<!-- 缓存配置 
       name:缓存名称。 
       maxElementsInMemory:缓存最大个数。 
       eternal:对象是否永久有效,一但设置了,timeout将不起作用。 
       timeToIdleSeconds:设置对象在失效前的允许闲置时间(单位:秒)。仅当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。 
       timeToLiveSeconds:设置对象在失效前允许存活时间(单位:秒)。最大时间介于创建时间和失效时间之间。仅当eternal=false对象不是永久有效时使用,默认是0.,也就是对象存活时间无穷大。 
       overflowToDisk:当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。 
       diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区。 
       maxElementsOnDisk:硬盘最大缓存个数。 
       diskPersistent:是否缓存虚拟机重启期数据 Whether the disk store persists between restarts of the Virtual Machine. The default value is false. 
       diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。 
       memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)。 
       clearOnFlush:内存数量最大时是否清除。 
-->
    <diskStore path="java.io.tmpdir" />
<!--     <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
        properties="connect=TCP(bind_port=50062):  
                    TCPPING(initial_hosts=    192.168.1.16[50061],
                                            192.168.1.16[50062];
                                            port_range=1;timeout=5000;num_initial_members=2)
                    MERGE2(min_interval=3000;max_interval=5000):  
                    FD_ALL(interval=5000;timeout=20000):
                    FD(timeout=3000;max_tries=3;):
                    VERIFY_SUSPECT(timeout=1500):
                    pbcast.NAKACK(retransmit_timeout=100,200,300,600,1200,2400,4800;discard_delivered_msgs=true):
                    pbcast.STABLE(stability_delay=1000;desired_avg_gossip=20000;max_bytes=0):
                    pbcast.GMS(print_local_addr=true;join_timeout=5000)"
        propertySeparator="::" /> -->
        <!-- 采用UDP多播方式集群 
        <cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
            properties="connect=UDP(mcast_addr=231.12.21.133;mcast_port=45566;):PING:
            MERGE2:FD_SOCK:VERIFY_SUSPECT:pbcast.NAKACK:UNICAST:pbcast.STABLE:FRAG:pbcast.GMS"
            propertySeparator="::" /> -->

    <!-- 默认缓存策略 -->
    <defaultCache 
        eternal="false"
        maxElementsInMemory="1000"
        overflowToDisk="false" 
        diskPersistent="false" 
        timeToIdleSeconds="10"
        timeToLiveSeconds="10" 
        memoryStoreEvictionPolicy="LFU">
    </defaultCache>

    <!-- 用户信息 -->
    <cache 
        name="userCache" 
        eternal="false" 
        maxElementsInMemory="500"
        overflowToDisk="false" 
        diskPersistent="false" 
        timeToIdleSeconds="1800"
        timeToLiveSeconds="0" 
        memoryStoreEvictionPolicy="LFU">
        <!-- 若不配置此类服务器重启后将不会同步缓存到本节点 
        <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory" properties="bootstrapAsynchronously=true" />
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"/>
        -->
    </cache>

    <!-- 医生信息 -->
    <cache 
        name="adminUserCache" 
        eternal="false" 
        maxElementsInMemory="500"
        overflowToDisk="false" 
        diskPersistent="false" 
        timeToIdleSeconds="1800"
        timeToLiveSeconds="0" 
        memoryStoreEvictionPolicy="LFU">
        <!-- 若不配置此类服务器重启后将不会同步缓存到本节点 
        <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory" properties="bootstrapAsynchronously=true" />
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"/>
        -->
    </cache>

    <!-- 验证码信息 -->
    <cache 
        name="codeCache" 
        eternal="false" 
        maxElementsInMemory="500"
        overflowToDisk="true" 
        diskPersistent="false" 
        timeToIdleSeconds="120"
        timeToLiveSeconds="1800" 
        memoryStoreEvictionPolicy="LFU">
        <!-- 若不配置此类服务器重启后将不会同步缓存到本节点 
        <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory" properties="bootstrapAsynchronously=true" />
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"/>
        -->
    </cache>

    <!-- 权限信息 -->
    <cache 
        name="permissionCache" 
        eternal="true" 
        maxElementsInMemory="500"
        overflowToDisk="true" 
        diskPersistent="false" 
        timeToIdleSeconds="0"
        timeToLiveSeconds="0" 
        memoryStoreEvictionPolicy="LFU">
        <!-- 若不配置此类服务器重启后将不会同步缓存到本节点 
        <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory" properties="bootstrapAsynchronously=true" />
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"/>
        -->
    </cache>
</ehcache>
原文地址:https://www.cnblogs.com/zf29506564/p/5805702.html