标签:
1:问题描述
项目用了spring数据源动态切换,服务用的是dubbo。在运行一段时间后程序异常,更新操作没有切换到主库上。这个问题在先调用读操作后再调用写操作会出现。经分析原因有3: 第一:当程序运行一段时间后调用duboo服务时,读操作与写操作有可能会在一个线程里,当这种情况出现时
2:数据源配置
<idclass> <name> <key-type> <keyvalue-ref/> <keyvalue-ref/> </> </> <nameref/> </>
<idtransaction-manager> <> <namepropagation/> <namepropagation/> <namepropagation/> <namepropagation/> <namepropagation/> <namepropagation/> <namepropagation/> <namepropagationread-only/> <namepropagationread-only/> <namepropagationread-only/> </> </>
<> <pointcutadvice-ref/> </> <idclass/> <> <pointcutadvice-ref/> </>
com.flzc.user.aop; org.slf4j.Logger; org.springframework.aop.AfterReturningAdvice; org.springframework.aop.MethodBeforeAdvice; org.springframework.aop.ThrowsAdvice; java.lang.reflect.Method; DataSourceAdvice MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice { Logger = org.slf4j.LoggerFactory.(DataSourceAdvice.); before(Method method, Object[] args, Object target) Throwable { .info(+ target.().getName() + + method.getName() + ); (method.getName().startsWith() || method.getName().startsWith() || method.getName().startsWith() || method.getName().startsWith() || method.getName().startsWith() || method.getName().startsWith() || method.getName().startsWith()) { DataSourceSwitcher.(); .info(); } { DataSourceSwitcher.(); .info(); } } afterReturning(Object arg0, Method method, Object[] args, Object target) Throwable { .info(+ target.().getName() + + method.getName() + ); } afterThrowing(Method method, Object[] args, Object target, Exception ex) Throwable { DataSourceSwitcher.(); .error(); } }
标签:
原文地址:http://my.oschina.net/mrXhuangyang/blog/500743