mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
修改设置问题
This commit is contained in:
parent
0a2e2f9799
commit
e5fecf7ed8
@ -71,11 +71,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>2.14.2</version>
|
||||
</dependency>
|
||||
<!--optional end-->
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.mybatisflex.core.datasource;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@ -26,12 +25,12 @@ public class DataSourceKey {
|
||||
/**
|
||||
* 通过注解设置的 key
|
||||
*/
|
||||
private static final ThreadLocal<String> annotationKeyThreadLocal = new TransmittableThreadLocal<>();
|
||||
private static ThreadLocal<String> annotationKeyThreadLocal = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 通过手动编码指定的 key
|
||||
*/
|
||||
private static final ThreadLocal<String> manualKeyThreadLocal = new TransmittableThreadLocal<>();
|
||||
private static ThreadLocal<String> manualKeyThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static String manualKey;
|
||||
|
||||
@ -82,4 +81,11 @@ public class DataSourceKey {
|
||||
return key != null ? key : annotationKeyThreadLocal.get();
|
||||
}
|
||||
|
||||
public static void setAnnotationKeyThreadLocal(ThreadLocal<String> annotationKeyThreadLocal) {
|
||||
DataSourceKey.annotationKeyThreadLocal = annotationKeyThreadLocal;
|
||||
}
|
||||
|
||||
public static void setManualKeyThreadLocal(ThreadLocal<String> manualKeyThreadLocal) {
|
||||
DataSourceKey.manualKeyThreadLocal = manualKeyThreadLocal;
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +108,12 @@
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>2.14.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.mybatisflex.core.MybatisFlexBootstrap;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.audit.ConsoleMessageCollector;
|
||||
@ -20,6 +21,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
public class MultiThreadsTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
DataSourceKey.setAnnotationKeyThreadLocal(new TransmittableThreadLocal<>());
|
||||
DataSourceKey.setManualKeyThreadLocal(new TransmittableThreadLocal<>());
|
||||
DataSource dataSource = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("db1")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user