springmvc my batis 다 중 데이터 원본 트 랜 잭 션 이 유효 하지 않 습 니 다.
8621 단어 mybatis사무.다 중 데이터 원본자바springmvc
, 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
>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
MySQL/마이바티스 | 동적 쿼리 사용A라는 서비스에 해당하는 테이블을 조인하고 조회하는 데 사용됩니다. 나중에 공통화를 위해 B 및 C 서비스도 추가됩니다. A, B, C 서비스는 모두 단일 쿼리에서 작동할 수 있도록 공통화되어야 합니다. 테이블에 각...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.