12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?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"
- 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">
- <!--扫描组件-->
- <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>
- <!--
- 开启事务的注解驱动
- 将使用@Transactional注解所标识的方法或类中所有的方法使用事务进行管理
- 如果@Transactional加在类上,那么这个类中所有的方法都是连接点
- transaction-manager属性设置事务管理器的id
- 若事务管理器的bean的id默认为transactionManager,则该属性可以不写
- -->
- <!--作用:将当前的事务管理器(也就是切面)里的通知作用到连接点上-->
- <!--补充:在spring的配置文件中,如果某个属性的值使用的是默认值,那么当前这个值就会变成灰色-->
- <tx:annotation-driven transaction-manager="transactionManager" />
- </beans>
|