spring.xml中的配置

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <beans xmlns="http://www.springframework.org/schema/beans"
  3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  4     xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
  5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
  6                         http://www.springframework.org/schema/beans/spring-beans.xsd
  7                         http://www.springframework.org/schema/aop 
  8                         http://www.springframework.org/schema/aop/spring-aop.xsd
  9                         http://www.springframework.org/schema/context 
 10                         http://www.springframework.org/schema/context/spring-context.xsd
 11                         http://www.springframework.org/schema/tx 
 12                         http://www.springframework.org/schema/tx/spring-tx.xsd">
 13 
 14     <!-- 启用注解 -->
 15     <context:annotation-config />
 16 
 17     <!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 -->
    //base-package中的属性是controller所在的路径
 18     <context:component-scan base-package="cn.ms.smartapp.xdhsop">
 19         <context:exclude-filter type="annotation"
 20             expression="org.springframework.stereotype.Controller" />
 21     </context:component-scan>
 22 
 23     <!-- 事务管理器 -->
 24     <bean name="transactionManager"
 25         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 26         <property name="dataSource" ref="dataSource"></property>
 27     </bean>
 28 
 29     <bean id="propertyConfigurer"
 30         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 31         <property name="locations">
 32             <list>
 33                 <value>/WEB-INF/classes/dbconfig.properties</value>
 34             </list>
 35         </property>
 36     </bean>
 37 
 38     <!-- 阿里 druid数据库连接池 -->
 39     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
 40         destroy-method="close">
 41         <!-- 数据库基本信息配置 -->
 42         <property name="url" value="${url}" />
 43         <property name="username" value="${username}" />
 44         <property name="password" value="${password}" />
 45         <property name="driverClassName" value="${driverClassName}" />
 46         <property name="filters" value="${filters}" />
 47         <!-- 最大并发连接数 -->
 48         <property name="maxActive" value="${maxActive}" />
 49         <!-- 初始化连接数量 -->
 50         <property name="initialSize" value="${initialSize}" />
 51         <!-- 配置获取连接等待超时的时间 -->
 52         <property name="maxWait" value="${maxWait}" />
 53         <!-- 最小空闲连接数 -->
 54         <property name="minIdle" value="${minIdle}" />
 55         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
 56         <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
 57         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
 58         <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
 59         <property name="validationQuery" value="${validationQuery}" />
 60         <property name="testWhileIdle" value="${testWhileIdle}" />
 61         <property name="testOnBorrow" value="${testOnBorrow}" />
 62         <property name="testOnReturn" value="${testOnReturn}" />
 63         <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" />
 64         <!-- 打开removeAbandoned功能 -->
 65         <property name="removeAbandoned" value="${removeAbandoned}" />
 66         <!-- 1800秒,也就是30分钟 -->
 67         <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
 68         <!-- 关闭abanded连接时输出错误日志 -->
 69         <property name="logAbandoned" value="${logAbandoned}" />
 70     </bean>
 71 
 72     <tx:advice id="txAdvice" transaction-manager="transactionManager">
 73         <tx:attributes>
 74             <tx:method name="delete*" propagation="REQUIRED" read-only="false"
 75                 rollback-for="java.lang.Exception" />
 76             <tx:method name="insert*" propagation="REQUIRED" read-only="false"
 77                 rollback-for="java.lang.Exception" />
 78             <tx:method name="update*" propagation="REQUIRED" read-only="false"
 79                 rollback-for="java.lang.Exception" />
 80             <tx:method name="save*" propagation="REQUIRED" read-only="false"
 81                 rollback-for="java.lang.Exception" />
 82         </tx:attributes>
 83     </tx:advice>
 84 
 85     <aop:aspectj-autoproxy proxy-target-class="true" />
 86 
 87     <!-- 事物处理 -->
 88     <aop:config>
 89         <aop:pointcut id="pc"
 90             expression="execution(* cn.ms.smartapp.xdhsop.service..*(..))" />
 91         <aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
 92     </aop:config>
 93 
 94     <!-- 配置mybatis -->
 95     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
 96         <property name="dataSource" ref="dataSource" />
 97         <property name="configLocation" value="classpath:mybatis/mybatisConfig.xml"></property>
 98         <!-- mapper扫描 -->
 99         <property name="mapperLocations" value="classpath:mybatis/*/*.xml"></property>
100     </bean>
101 
102     <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
103         <constructor-arg ref="sqlSessionFactory" />
104     </bean>
105 </beans>
原文地址:https://www.cnblogs.com/MrzhangKk/p/5274888.html