springmvc my batis 다 중 데이터 원본 트 랜 잭 션 이 유효 하지 않 습 니 다.

        ,           service,  springmvc                 ,  
     ,       。

                                         
         
masterDataSource,
slaveDataSource

<
bean
id
="masterDataSource"
class
="com.alibaba.druid.pool.DruidDataSource"
init-method
="init"
destroy-method
="close"
>
<
property
name
="driverClassName"
>
<
value
>${master.jdbc_driverClassName}
value
>
property
>
<
property
name
="url"
>
<
value
>${master.jdbc_url}
value
>
property
>
<
property
name
="username"
>
<
value
>${master.jdbc_username}
value
>
property
>
<
property
name
="password"
>
<
value
>${master.jdbc_password}
value
>
property
>
<
property
name
="maxActive"
>
<
value
>40
value
>
property
>
<
property
name
="initialSize"
>
<
value
>1
value
>
property
>
<
property
name
="maxWait"
>
<
value
>60000
value
>
property
>
<
property
name
="minIdle"
>
<
value
>3
value
>
property
>
<
property
name
="removeAbandoned"
>
<
value
>true
value
>
property
>
<
property
name
="removeAbandonedTimeout"
>
<
value
>180
value
>
property
>
<
property
name
="connectionProperties"
>
<
value
>clientEncoding=UTF-8
value
>
property
>
<
property
name
="validationQuery"
value
="SELECT 1"
/>
<
property
name
="testWhileIdle"
value
="true"
/>
<
property
name
="testOnBorrow"
value
="false"
/>
<
property
name
="testOnReturn"
value
="false"
/>
<
property
name
="timeBetweenEvictionRunsMillis"
value
="60000"
/>
<
property
name
="minEvictableIdleTimeMillis"
value
="100000"
/>
bean
>
<
bean
id
= "slaveDataSource"
class
= "com.alibaba.druid.pool.DruidDataSource"
init-method
= "init"
destroy-method
= "close"
>
<
property
name
= "driverClassName"
>
<
value
>${slave.jdbc_driverClassName}
value
>
property
>
<
property
name
= "url"
>
<
value
>${slave.jdbc_url}
value
>
property
>
<
property
name
= "username"
>
<
value
>${slave.jdbc_username}
value
>
property
>
<
property
name
= "password"
>
<
value
>${slave.jdbc_password}
value
>
property
>
<
property
name
= "maxActive"
>
<
value
>40
value
>
property
>
<
property
name
= "initialSize"
>
<
value
>1
value
>
property
>
<
property
name
= "maxWait"
>
<
value
>60000
value
>
property
>
<
property
name
= "minIdle"
>
<
value
>3
value
>
property
>
<
property
name
= "removeAbandoned"
>
<
value
>true
value
>
property
>
<
property
name
= "removeAbandonedTimeout"
>
<
value
>180
value
>
property
>
<
property
name
= "connectionProperties"
>
<
value
>clientEncoding=UTF-8
value
>
property
>
<
property
name
="validationQuery"
value
="SELECT 1"
/>
<
property
name
="testWhileIdle"
value
="true"
/>
<
property
name
="testOnBorrow"
value
="false"
/>
<
property
name
="testOnReturn"
value
="false"
/>
<
property
name
="timeBetweenEvictionRunsMillis"
value
="60000"
/>
<
property
name
="minEvictableIdleTimeMillis"
value
="100000"
/>
bean
>
동적 전환 설정
 
<
bean
id
= "dataSource"
class
= "com.remair.hx.readwrite.DynamicDataSource"
>
<
property
name
= "targetDataSources"
>
<
map
key-type
= "java.lang.String"
>
<
entry
value-ref
= "masterDataSource"
key
= "masterDataSource"
>
entry
>
<
entry
value-ref
= "slaveDataSource"
key
= "slaveDataSource"
>
entry
>
map
>
property
>
<
property
name
= "defaultTargetDataSource"
ref
= "masterDataSource"
>
property
>
bean
>op 오픈
<
aop
:aspectj-autoproxy
proxy-target-class
="true"
/>차단기 설정
<
bean
id
="dataSourceAop"
class
="com.remair.hx.aspect.DataSourceAop"
/>
<
aop
:config
>
<
aop
:aspect
id
="c"
ref
="dataSourceAop"
>
<
aop
:pointcut
id
="tx"
expression
="execution(* com.remair.hx.api.*.business.*.*(..))"
/>
<
aop
:before
pointcut-ref
="tx"
method
="before"
/>
aop
:aspect
>
aop
:config
>다음 에 인 용 된 datasource-ref 는 전체 dataSource 와
transactionManager     dataSource    

<
bean
id
="sqlSessionFactory"
class
="org.mybatis.spring.SqlSessionFactoryBean"
p
:dataSource-ref
="dataSource"
p
:mapperLocations
="classpath:mapper/*.xml"
/>
<
bean
class
="org.mybatis.spring.mapper.MapperScannerConfigurer"
p
:basePackage
="com.remair.hx.mapper"
p
:sqlSessionFactoryBeanName
="sqlSessionFactory"
/>
<
bean
id
="transactionManager"
class
="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p
:dataSource-ref
="dataSource"
>
<
qualifier
value
="master"
>
qualifier
>
bean
>
<
tx
:annotation-driven
transaction-manager
="transactionManager"
proxy-target-class
="true"
>
tx
:annotation-driven
>

좋은 웹페이지 즐겨찾기