diff --git a/CHANGELOG.md b/CHANGELOG.md
index 798713d214..3dedc8ec53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,25 @@
# Change Log
+## v2.0.1-SNAPSHOT (Unreleased)
+
+### Breaking Changes
+
+- **deps**: Upgrade slf4j-api from 1.7.36 to 2.0.17 for Spring Boot 3.5.0 compatibility
+- **deps**: Upgrade logback from 1.2.13 to 1.4.14 for SLF4J 2.0 support
+- **deps**: Replace log4j-slf4j-impl with log4j-slf4j2-impl (2.24.3) for SLF4J 2.0 bridge
+
+### Enhancements
+
+- **core**: Implement SLF4J 2.0 new MDCAdapter interface methods (pushByKey, popByKey, clearDequeByKey, getCopyOfDequeByKey) in TrpcMDCAdapter
+- **core**: Use reflection to initialize MDC adapter in SLF4J 2.0 compatible way
+- **deps**: Ensure all slf4j dependencies are upgraded to 2.0.17 across all modules
+
+### Compatibility
+
+- **java**: Fully compatible with JDK 17
+- **spring**: Fully compatible with Spring Boot 3.5.0
+- **jakarta**: Aligned with Jakarta EE 10
+
## v1.1.0 (2023-12-20)
### Features
diff --git a/trpc-code-generator/pom.xml b/trpc-code-generator/pom.xml
index 4402725d42..1c996b247b 100644
--- a/trpc-code-generator/pom.xml
+++ b/trpc-code-generator/pom.xml
@@ -26,7 +26,7 @@
org.apache.logging.log4j
- log4j-slf4j-impl
+ log4j-slf4j2-impl
diff --git a/trpc-core/pom.xml b/trpc-core/pom.xml
index 362168d06d..9d4f20b70c 100644
--- a/trpc-core/pom.xml
+++ b/trpc-core/pom.xml
@@ -50,7 +50,7 @@
org.apache.logging.log4j
- log4j-slf4j-impl
+ log4j-slf4j2-impl
org.slf4j
diff --git a/trpc-core/src/main/java/org/slf4j/TrpcMDCAdapter.java b/trpc-core/src/main/java/org/slf4j/TrpcMDCAdapter.java
index a93137b7ef..8b76ddcccc 100644
--- a/trpc-core/src/main/java/org/slf4j/TrpcMDCAdapter.java
+++ b/trpc-core/src/main/java/org/slf4j/TrpcMDCAdapter.java
@@ -13,6 +13,8 @@
import com.alibaba.ttl.TransmittableThreadLocal;
import com.tencent.trpc.core.utils.StringUtils;
+import java.util.Deque;
+import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -47,7 +49,15 @@ public class TrpcMDCAdapter implements MDCAdapter {
static {
mtcMDCAdapter = new TrpcMDCAdapter();
- MDC.mdcAdapter = mtcMDCAdapter;
+ try {
+ // In SLF4J 2.0, MDC.mdcAdapter is no longer directly accessible
+ // We need to use reflection to set it
+ Field field = MDC.class.getDeclaredField("mdcAdapter");
+ field.setAccessible(true);
+ field.set(null, mtcMDCAdapter);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to initialize TrpcMDCAdapter", e);
+ }
}
public static MDCAdapter init() {
@@ -143,9 +153,9 @@ public Map getCopyOfContextMap() {
@SuppressWarnings("unchecked")
@Override
- public void setContextMap(Map contextMap) {
+ public void setContextMap(Map contextMap) {
lastOperation.set(WRITE_OPERATION);
- Map newMap = new ConcurrentHashMap(contextMap);
+ Map newMap = new ConcurrentHashMap<>(contextMap);
// the newMap replaces the old one for serialisation's sake
copyOnInheritThreadLocal.set(newMap);
}
@@ -178,4 +188,77 @@ private Map duplicateAndInsertNewMap(Map oldMap)
return newMap;
}
+ /**
+ * Push a context value as identified with the key parameter into the current thread's context map.
+ * This is a SLF4J 2.0 new method for supporting MDC stack operations.
+ *
+ * @param key the key
+ * @param value the value to push
+ * @throws NullPointerException in case the "key" parameter is null
+ */
+ @Override
+ public void pushByKey(String key, String value) {
+ Objects.requireNonNull(key, "key cannot be null");
+ Map oldMap = copyOnInheritThreadLocal.get();
+ Integer lastOp = getAndSetLastOperation();
+ if (wasLastOpReadOrNull(lastOp) || oldMap == null) {
+ Map newMap = duplicateAndInsertNewMap(oldMap);
+ newMap.put(key, value);
+ } else {
+ oldMap.put(key, value);
+ }
+ }
+
+ /**
+ * Pop the context identified by key parameter from the current thread's context map.
+ * This is a SLF4J 2.0 new method for supporting MDC stack operations.
+ *
+ * @param key the key
+ * @return the value removed, or null if there was no value for the key
+ * @throws NullPointerException in case the "key" parameter is null
+ */
+ @Override
+ public String popByKey(String key) {
+ Objects.requireNonNull(key, "key cannot be null");
+ Map oldMap = copyOnInheritThreadLocal.get();
+ if (oldMap == null) {
+ return null;
+ }
+ Integer lastOp = getAndSetLastOperation();
+ if (wasLastOpReadOrNull(lastOp)) {
+ Map newMap = duplicateAndInsertNewMap(oldMap);
+ return newMap.remove(key);
+ } else {
+ return oldMap.remove(key);
+ }
+ }
+
+ /**
+ * Clear all the entries in the deque identified by the key parameter.
+ * This is a SLF4J 2.0.7+ new method for clearing MDC stacks.
+ *
+ * @param key the key
+ * @throws NullPointerException in case the "key" parameter is null
+ */
+ @Override
+ public void clearDequeByKey(String key) {
+ Objects.requireNonNull(key, "key cannot be null");
+ remove(key);
+ }
+
+ /**
+ * Get a copy of the deque identified by the key parameter.
+ * This is a SLF4J 2.0 new method for supporting MDC stack operations.
+ * Since our implementation uses a simple Map, we return null to indicate no deque.
+ *
+ * @param key the key
+ * @return null (this implementation does not support deques)
+ */
+ @Override
+ public Deque getCopyOfDequeByKey(String key) {
+ // This implementation uses a simple Map structure, not Deque
+ // Return null to indicate no deque exists for the key
+ return null;
+ }
+
}
\ No newline at end of file
diff --git a/trpc-dependencies/trpc-dependencies-bom/pom.xml b/trpc-dependencies/trpc-dependencies-bom/pom.xml
index 2372502aa2..23680a84a0 100644
--- a/trpc-dependencies/trpc-dependencies-bom/pom.xml
+++ b/trpc-dependencies/trpc-dependencies-bom/pom.xml
@@ -103,7 +103,7 @@
3.28.0-GA
3.1.0
3.0.2
- 1.2.13
+ 1.4.14
2.24.3
1.3.3
3.1.0
@@ -137,7 +137,7 @@
1.8.6
1.8.6
- 1.7.36
+ 2.0.17
2.0
1.1.10.4
6.2.7
diff --git a/trpc-logger/trpc-logger-admin/pom.xml b/trpc-logger/trpc-logger-admin/pom.xml
index 048baa3be9..30f0ff605c 100644
--- a/trpc-logger/trpc-logger-admin/pom.xml
+++ b/trpc-logger/trpc-logger-admin/pom.xml
@@ -30,7 +30,7 @@
org.apache.logging.log4j
- log4j-slf4j-impl
+ log4j-slf4j2-impl
ch.qos.logback
diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/pom.xml b/trpc-spring-boot-starters/trpc-spring-boot-starter/pom.xml
index 064cebf9a9..d44e63f2b3 100644
--- a/trpc-spring-boot-starters/trpc-spring-boot-starter/pom.xml
+++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/pom.xml
@@ -27,7 +27,7 @@
slf4j-log4j12
- log4j-slf4j-impl
+ log4j-slf4j2-impl
org.apache.logging.log4j