<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <context:property-placeholder location="classpath:config/jdbc.properties" /> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxWait" value="20000"></property> <property name="maxActive"><value>20</value></property> <property name="maxIdle"><value>20</value></property> <property name="minIdle"><value>3</value></property> <property name="minevictableIdleTimeMillis" value="120000"></property> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout"><value>500</value></property> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow"><value>false</value></property> <property name="testOnReturn"><value>false</value></property> <property name="validationQuery"><value>select sysdate from dual</value></property> <property name="timeBetweenevictionRunsMillis"><value>30000</value></property> <property name="numTestsPerevictionRun"><value>20</value></property> </bean> --> <bean id="master" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url.w}" /> <property name="user" value="${jdbc.username.w}" /> <property name="password" value="${jdbc.password.w}" /> <property name="minPoolSize" value="${jdbc.miniPoolSize}" /> <property name="maxPoolSize" value="${jdbc.maxPoolSize}" /> <property name="initialPoolSize" value="${jdbc.initialPoolSize}" /> <property name="maxIdleTime" value="${jdbc.maxIdleTime}" /> <property name="acquireIncrement" value="${jdbc.acquireIncrement}" /> <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" /> <property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}" /> <property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}" /> <property name="automaticTestTable" value="${jdbc.automaticTestTable}" /> <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" /> <property name="checkoutTimeout" value="${jdbc.checkoutTimeout}" /> </bean> <bean id="slave" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url.r}" /> <property name="user" value="${jdbc.username.r}" /> <property name="password" value="${jdbc.password.r}" /> <property name="minPoolSize" value="${jdbc.miniPoolSize}" /> <property name="maxPoolSize" value="${jdbc.maxPoolSize}" /> <property name="initialPoolSize" value="${jdbc.initialPoolSize}" /> <property name="maxIdleTime" value="${jdbc.maxIdleTime}" /> <property name="acquireIncrement" value="${jdbc.acquireIncrement}" /> <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" /> <property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}" /> <property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}" /> <property name="automaticTestTable" value="${jdbc.automaticTestTable}" /> <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" /> <property name="checkoutTimeout" value="${jdbc.checkoutTimeout}" /> </bean> <beans:bean id="myDataSource" class="com.xb.core.datasource.ReplicationDataSource"> <property name="targetDataSources"> <map key-type="java.lang.String"> <!-- write --> <entry key="master" value-ref="master" /> <!-- read --> <entry key="slave" value-ref="slave" /> </map> </property> <property name="defaultTargetDataSource" ref="master" /> <!--<property name="dataWrite" ref="dataSourceW" /> <property name="dataRead" ref="dataSourceR"/> <list> <ref bean="dataSource2" /> <ref bean="dataSource3" /> </list> </property> --> </beans:bean> <!-- sqlSessionfactorybean是用于创建sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.sqlSessionfactorybean"> <property name="dataSource" ref="myDataSource" /> <property name="mapperLocations" value="classpath:com/xb/mapper/*.xml" /> <property name="typeAliasesPackage" value="com.xb.model" /> </bean> <!-- 自动扫描包的方式 来注册Mapper --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.xb.dao" /> </bean> <!-- 配置需要被Spring管理的Bean(创建,创建后放在了Spring IOC容器里面) --> <!-- 自动扫描dao和service和 action包(自动注入) --> <context:component-scan base-package="com.xb" use-default-filters="false"> <!-- 扫描符合@Service @Repository @Controller的类 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" /> <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" /> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 --> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <!-- 1.注解方式配置事务 --> <!-- 开启注解配置 --> <context:annotation-config /> <!-- 开启事务注解驱动 --> <tx:annotation-driven /> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="myDataSource" /> </bean> <aop:aspectj-autoproxy proxy-target-class="true" /> <beans:bean id="replicationDataSourceAspect" class="com.xb.core.datasource.ReplicationDataSourceAspect" /> <aop:config> <aop:aspect id="c" ref="replicationDataSourceAspect"> <aop:pointcut id="mapperTx" expression="execution(* com.xb.service.*.*.*(..))" /> <aop:before pointcut-ref="mapperTx" method="before" /> </aop:aspect> </aop:config> </beans>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。