Closed pan-common closed 4 years ago
JDK Version(required): 1.8
SpringBoot Version(required): 2.2.5.RELEASE
dynamic-datasource-spring-boot-starter Version(required): 2.2.5.RELEASE
druid Version(optional): 1.1.20
3台服务器通过nginx负载均衡,一个执行需要5秒左右的方法中做了动态切换数据源,连续点击按钮调用这个方法数据源切换之后切不回来。最终会造成所有服务都因为切换了数据源无法正常访问。 代码如下:
try { if(zxjcjgEntity.getJcrq()!=null) { year = DateUtil.format(zxjcjgEntity.getJcrq(), "yyyy"); }else if(zxjcjgEntity.getKsrq()!=null) { year = DateUtil.format(zxjcjgEntity.getKsrq(), "yyyy"); } DynamicDataSourceContextHolder.push("jcpt_"+year); return invocation.proceed(); }finally { DynamicDataSourceContextHolder.push("master"); }
数据源切换是和服务绑定的还是用户当前用户打开的数据库连接? 有没有办法避免一个用户的操作使整个服务出错? Expected Result:
Actual Result:
Step 1
Step 2
Step 3
finally不应该是关闭吗?
你一个线程完了不清空还要往里面push,下一个进来了当然会影响
Enviroment
JDK Version(required): 1.8
SpringBoot Version(required): 2.2.5.RELEASE
dynamic-datasource-spring-boot-starter Version(required): 2.2.5.RELEASE
druid Version(optional): 1.1.20
Describe
3台服务器通过nginx负载均衡,一个执行需要5秒左右的方法中做了动态切换数据源,连续点击按钮调用这个方法数据源切换之后切不回来。最终会造成所有服务都因为切换了数据源无法正常访问。 代码如下:
数据源切换是和服务绑定的还是用户当前用户打开的数据库连接? 有没有办法避免一个用户的操作使整个服务出错? Expected Result:
Actual Result:
Steps to reproduce
Step 1
Step 2
Step 3