1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?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:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
- <!--扫描组件-->
- <context:component-scan base-package="com.cdxw.spring"></context:component-scan>
- <!--引入外部属性文件jdbc.properties-->
- <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
- <!--配置数据源-->
- <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
- <property name="driverClassName" value="${jdbc.driver}"></property>
- <property name="url" value="${jdbc.url}"></property>
- <property name="username" value="${jdbc.username}"></property>
- <property name="password" value="${jdbc.password}"></property>
- </bean>
- <!--配置JdbcTemplate-->
- <bean class="org.springframework.jdbc.core.JdbcTemplate">
- <!--装配数据源-->
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!--配置事务管理器-->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!--配置事务通知-->
- <tx:advice id="tx" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="buyBook"/>
- <tx:method name="*"/>
- </tx:attributes>
- </tx:advice>
- <aop:config>
- <aop:advisor advice-ref="tx" pointcut="execution(* com.cdxw.spring.service.impl.*.*(..))"></aop:advisor>
- </aop:config>
- </beans>
|