1.定义DataSource 配置
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true& characterEncoding=utf-8&mysqlEncoding=utf8
</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>test</value>
</property>
</bean>
2.定义transactionManager 配置
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
3.定义UserDao 配置
<bean id="userDao" class="entity.UserDaoImp"> //我们自己写的UserDaoImp 所以属性名可以更改
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
4.定义UserDaoProxy 配置
<bean id="userDaoProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="userDao"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>