<? xml version = "1.0" encoding = "UTF-8" ?>
< beans xmlns = "http://www./schema/beans"
xmlns:xsi = "http://www./2001/XMLSchema-instance"
xmlns:context = "http://www./schema/context"
xmlns:tx = "http://www./schema/tx"
xmlns:aop = "http://www./schema/aop"
xmlns:mvc = "http://www./schema/mvc"
xmlns:jee = "http://www./schema/jee"
xsi:schemaLocation="http://www./schema/mvc
http://www./schema/mvc/spring-mvc-3.1.xsd
http://www./schema/tx
http://www./schema/tx/spring-tx-3.0.xsd
http://www./schema/aop
http://www./schema/aop/spring-aop-3.0.xsd
http://www./schema/beans
http://www./schema/beans/spring-beans-3.0.xsd
http://www./schema/context
http://www./schema/context/spring-context-3.0.xsd
http://www./schema/jee
http://www./schema/jee/spring-jee-3.0.xsd">
<!-- 打开基于注解的配置 -->
< context:annotation-config />
< aop:aspectj-autoproxy />
<!-- 开启组件自动扫描 -->
< context:component-scan base-package = "org.rsun.ams" />
<!-- 读取外部属性文件 -->
< context:property-placeholder location = "classpath:DataSource.properties" />
<!-- 配置数据源 -->
< bean id = "dataSource" class = "com.alibaba.druid.pool.DruidDataSource"
init-method = "init" destroy-method = "close" >
<!-- 初始化连接数量; -->
< property name = "initialSize" value = "0" />
<!-- 最大并发连接数 -->
< property name = "maxActive" value = "20" />
<!-- 最大空闲连接数 -->
< property name = "maxIdle" value = "20" />
<!-- 最小空闲连接数 -->
< property name = "minIdle" value = "0" />
<!-- 最大等待时长 -->
< property name = "maxWait" value = "60000" />
<!-- 超过时间限制是否回收 -->
< property name = "removeAbandoned" value = "true" />
<!-- 超过时间限制多长; -->
< property name = "removeAbandonedTimeout" value = "180" />
<!-- 数据源连接参数配置; -->
< property name = "username" value = "${username}" />
< property name = "url" value = "${url}" />
< property name = "password" value = "${password}" />
< property name = "driverClassName" value = "${driverClassName}" />
</ bean >
<!-- 配置SessionFactory -->
< bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
< property name = "dataSource" ref = "dataSource" />
< property name = "packagesToScan" value = "org.rsun.ams.core.model" />
< property name = "hibernateProperties" >
< props >
< prop key = "hibernate.dialect" >${hibernate.dialect}</ prop >
< prop key = "hibernate.show_sql" >${hibernate.show_sql}</ prop >
< prop key = "hibernate.hbm2ddl.auto" >${hibernate.hbm2ddl.auto}</ prop >
< prop key = "hibernate.format_sql" >${hibernate.format_sql}</ prop >
</ props >
</ property >
</ bean >
<!-- 配置事务管理器 -->
< bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager" >
< property name = "sessionFactory" ref = "sessionFactory" />
</ bean >
<!-- 定义切面 -->
< aop:config >
< aop:pointcut expression = "execution(* org.rsun.ams.service.*.* (..))" id = "txPointCut" />
< aop:advisor advice-ref = "txAdvice" pointcut-ref = "txPointCut" />
</ aop:config >
<!-- 声明式事务 -->
< tx:advice id = "txAdvice" transaction-manager = "transactionManager" >
< tx:attributes >
< tx:method name = "add*" propagation = "REQUIRED" />
< tx:method name = "remove*" propagation = "REQUIRED" />
< tx:method name = "update*" propagation = "REQUIRED" />
< tx:method name = "init*" propagation = "REQUIRED" />
< tx:method name = "*" read-only = "true" propagation = "REQUIRED" />
</ tx:attributes >
</ tx:advice >
<!-- 开启事务注解
<tx:annotation-driven transaction-manager="transactionManager"/>
-->
</ beans >
|