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" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:aop="http://www.springframework.org/schema/aop" 6 xmlns:tx="http://www.springframework.org/schema/tx" 7 xsi:schemaLocation=" 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context-3.2.xsd 12 http://www.springframework.org/schema/aop 13 http://www.springframework.org/schema/aop/spring-aop.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 16 17 <!-- 扫描包基础目录 --> 18 <context:component-scan base-package="com.wisezone"></context:component-scan> 19 20 <!-- 加载properties 配置文件 --> 21 <context:property-placeholder location="db.properties"/> 22 23 <!-- c3p0数据源配置 --> 24 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 25 <property name="driverClass" value="${driver}"></property> 26 <property name="jdbcUrl" value="${url}"></property> 27 <property name="user" value="${user}"></property> 28 <property name="password" value="${password}"></property> 29 </bean> 30 31 <!-- jdbc模板类配置 --> 32 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 33 <!-- 属性名称固定 --> 34 <property name="dataSource" ref="dataSource"></property> 35 </bean> 36 37 <aop:aspectj-autoproxy/> 38 39 <!-- 事物管理器配置 --> 40 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 41 <property name="dataSource" ref="dataSource"></property> 42 </bean> 43 44 <!-- 配置事物通知 --> 45 <tx:advice id="txAdvice" transaction-manager="txManager"> 46 <tx:attributes> 47 <tx:method name="save*" propagation="REQUIRED"/> 48 <tx:method name="update*" propagation="REQUIRED"/> 49 <tx:method name="del*" propagation="REQUIRED"/> 50 </tx:attributes> 51 </tx:advice> 52 53 <!-- 切面配置 --> 54 <aop:config> 55 <!-- ..:表示service下所有子包 (..):表示拦截的东西 --> 56 <aop:pointcut expression="execution (* com.wisezone.service..*.*(..))" id="cut"/> 57 <aop:advisor advice-ref="txAdvice" pointcut-ref="cut"/> 58 </aop:config> 59 </beans>
转载于:https://www.cnblogs.com/wdh1995/p/6792175.html