<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byType">
<!-- 配置自动扫描路径扫描类中的元注释来实现bean管理 -->
<context:component-scan base-package="com.zk.oa.dao.impl" />
<context:component-scan base-package="com.zk.oa.service.impl" />
<!-- 配置C3P0 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="user" value="zk"></property>
<property name="password" value="zk"></property>
</bean>
<!-- 事务管理器(声明式事务) -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 定义一个事务切面 ,使用tx标签配置的拦截器-->
<!-- 配置事务传播特性 -->
<tx:advice id="transAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- AOP代理 -->
<aop:config>
<!-- 定义切点 -->
<aop:pointcut expression="execution(* com.zk.oa.service.*.*(..))"
id="servicePoint" />
<!-- 为切点植入事务切面 -->
<aop:advisor advice-ref="transAdvice" pointcut-ref="servicePoint" />
</aop:config>
</beans>
转载于:https://blog.51cto.com/cube0/870122