spring datasourses 配置
<beans> <bean name="datasource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:3307:test"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> <bean name="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="datasource"/> </bean>
<tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.javass..business.ebo.*Ebo.*(..))"/> </aop:config> </beans>
DataSourceTransactionManager类,
属性:一个manager对应一个dataSource
package org.springframework.jdbc.datasource; public class DataSourceTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean {
@Nullable private DataSource dataSource; private boolean enforceReadOnly = false; ... ... ... }