From 293e0975d00e237308dbed326d71f6a03a457831 Mon Sep 17 00:00:00 2001
From: Haotian Zhang <928016560@qq.com>
Date: Mon, 29 Jul 2024 16:39:07 +0800
Subject: [PATCH 1/5] feat:update example with log4j2.
---
.../quickstart-examples/provider-a/pom.xml | 232 +++++++++---------
.../quickstart-examples/provider/pom.xml | 12 +
.../quickstart-examples/provider-a/pom.xml | 217 ++++++++--------
...cation.properties => bootstrap.properties} | 0
4 files changed, 235 insertions(+), 226 deletions(-)
rename polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-b/src/main/resources/{application.properties => bootstrap.properties} (100%)
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml
index 00e5b00a..e1c08e36 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml
@@ -1,119 +1,121 @@
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.1.7
-
-
- 4.0.0
-
- com.tencent.polaris
- polaris-javaagent-demo-sc-quickstart-2022-provider-a
- jar
- 1.7.0
-
- 2022-provider-a
- Demo Provider Project For Spring Cloud Alibaba
-
-
-
-
- com.alibaba.cloud
- spring-cloud-alibaba-dependencies
- 2022.0.0.0
- pom
- import
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- 2022.0.4
- pom
- import
-
-
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-starter-bootstrap
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-discovery
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-config
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-webflux
-
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- true
-
-
-
-
- repackage
-
-
-
-
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.1.7
+
+
+ 4.0.0
+
+ com.tencent.polaris
+ polaris-javaagent-demo-sc-quickstart-2022-provider-a
+ jar
+ 1.7.0
+
+ 2022-provider-a
+ Demo Provider Project For Spring Cloud Alibaba
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-alibaba-dependencies
+ 2022.0.0.0
+ pom
+ import
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2022.0.4
+ pom
+ import
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+
+
+
+
+ repackage
+
+
+
+
+
+
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml
index b4336068..2490b2dc 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml
@@ -42,9 +42,21 @@
org.springframework.cloud
spring-cloud-starter-bootstrap
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
org.springframework.boot
spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
index 08eb4986..d71e5a15 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
@@ -1,115 +1,110 @@
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.3.7.RELEASE
-
-
- 4.0.0
-
- com.tencent.polaris
- polaris-javaagent-demo-sc-quickstart-hoxton-provider-a
- jar
- 1.7.0
-
- hoxton-provider-a
- Demo Provider Project For Spring Cloud Alibaba
-
-
-
-
- com.alibaba.cloud
- spring-cloud-alibaba-dependencies
- 2.2.10-RC2
- pom
- import
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- Hoxton.SR12
- pom
- import
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-discovery
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-config
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-webflux
-
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- true
-
-
-
-
- repackage
-
-
-
-
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.7.RELEASE
+
+
+ 4.0.0
+
+ com.tencent.polaris
+ polaris-javaagent-demo-sc-quickstart-hoxton-provider-a
+ jar
+ 1.7.0
+
+ hoxton-provider-a
+ Demo Provider Project For Spring Cloud Alibaba
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-alibaba-dependencies
+ 2.2.10-RC2
+ pom
+ import
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ Hoxton.SR12
+ pom
+ import
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+
+
+
+
+ repackage
+
+
+
+
+
+
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-b/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties
similarity index 100%
rename from polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-b/src/main/resources/application.properties
rename to polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties
From 83d8bcddac0b56f741bfdf6c8452f5b2f3348f57 Mon Sep 17 00:00:00 2001
From: Haotian Zhang <928016560@qq.com>
Date: Tue, 30 Jul 2024 16:09:22 +0800
Subject: [PATCH 2/5] fix:fix log framework conflict.
---
.../spring-cloud-2022-plugin/pom.xml | 30 +++-
.../agent/plugin/spring/cloud/MainPlugin.java | 162 +++++++++---------
.../SpringFactoriesLoaderInterceptor.java | 56 +++---
.../spring-cloud-2023-plugin/pom.xml | 31 +++-
.../SpringFactoriesLoaderInterceptor.java | 3 +-
.../spring-cloud-hoxton-plugin/pom.xml | 30 +++-
.../SpringFactoriesLoaderInterceptor.java | 6 +-
pom.xml | 2 +-
8 files changed, 193 insertions(+), 127 deletions(-)
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
index b04e4726..945cdf10 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
@@ -23,9 +23,25 @@
+
+ org.springframework.boot
+ spring-boot-starter-logging
+ provided
+
+
+ ch.qos.logback
+ logback-classic
+ provided
+
+
+ ch.qos.logback
+ logback-core
+ provided
+
org.springframework.boot
spring-boot-starter-web
+ provided
org.springframework.boot
@@ -61,10 +77,6 @@
spring-cloud-plugin-common
${project.version}
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
com.tencent.polaris
polaris-agent-core-extension
@@ -153,6 +165,16 @@
+
+ com.tencent.polaris
+ connector-nacos
+
+
+
+ com.tencent.polaris
+ connector-consul
+
+
com.tencent.polaris
connector-composite
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java
index 3eb1c820..d9238041 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java
@@ -17,8 +17,6 @@
package cn.polarismesh.agent.plugin.spring.cloud;
-import java.security.ProtectionDomain;
-
import cn.polarismesh.agent.core.extension.AgentPlugin;
import cn.polarismesh.agent.core.extension.PluginContext;
import cn.polarismesh.agent.core.extension.instrument.InstrumentClass;
@@ -33,6 +31,8 @@
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.RegisterBeanInterceptor;
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.SpringFactoriesLoaderInterceptor;
+import java.security.ProtectionDomain;
+
/**
* Polaris Spring Cloud hoxton Plugin
*
@@ -40,84 +40,84 @@
*/
public class MainPlugin implements AgentPlugin {
- public void init(PluginContext context) {
- System.setProperty(Constant.AGENT_CONF_PATH, context.getAgentDirPath());
- TransformOperations operations = context.getTransformOperations();
- addPolarisTransformers(operations);
- }
-
- /**
- * add polaris transformers
- */
- private void addPolarisTransformers(TransformOperations operations) {
-
- // 注入默认配置
- operations.transform(Constant.CONFIGURATION_CLAZZ_POST_PROCESSOR, ConfigurationPostProcessorTransform.class);
-
- // 注入bootstrap的bean定义
- operations.transform(Constant.CONFIGURATION_CLAZZ_PARSER, ConfigurationParserTransform.class);
-
- // 注入bean定义的调整设置
- operations.transform(Constant.BEAN_DEFINITION_REGISTRY, RegisterBeanDefinitionTransform.class);
-
- // 注入JNI定义
- operations.transform(Constant.SPRING_FACTORIES_LOADER, SpringFactoriesLoaderTransform.class);
- }
-
- public static class ConfigurationParserTransform implements TransformCallback {
-
- @Override
- public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
- InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
- InstrumentMethod constructMethod = target.getDeclaredMethod("parse", "java.util.Set");
- if (constructMethod != null) {
- constructMethod.addInterceptor(ConfigurationParserInterceptor.class);
- }
-
- return target.toBytecode();
- }
- }
-
- public static class ConfigurationPostProcessorTransform implements TransformCallback {
-
- @Override
- public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
- InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
- InstrumentMethod constructMethod = target.getDeclaredMethod("processConfigBeanDefinitions", "org.springframework.beans.factory.support.BeanDefinitionRegistry");
- if (constructMethod != null) {
- constructMethod.addInterceptor(ConfigurationPostProcessorInterceptor.class);
- }
-
- return target.toBytecode();
- }
- }
-
- public static class RegisterBeanDefinitionTransform implements TransformCallback {
-
- @Override
- public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
- InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
- InstrumentMethod constructMethod = target.getDeclaredMethod("registerBeanDefinition", "java.lang.String", "org.springframework.beans.factory.config.BeanDefinition");
- if (constructMethod != null) {
- constructMethod.addInterceptor(RegisterBeanInterceptor.class);
- }
-
- return target.toBytecode();
- }
- }
-
- public static class SpringFactoriesLoaderTransform implements TransformCallback {
-
- @Override
- public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
- InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
- InstrumentMethod constructMethod = target.getDeclaredMethod("loadSpringFactories", "java.lang.ClassLoader");
- if (constructMethod != null) {
- constructMethod.addInterceptor(SpringFactoriesLoaderInterceptor.class);
- }
-
- return target.toBytecode();
- }
- }
+ public void init(PluginContext context) {
+ System.setProperty(Constant.AGENT_CONF_PATH, context.getAgentDirPath());
+ TransformOperations operations = context.getTransformOperations();
+ addPolarisTransformers(operations);
+ }
+
+ /**
+ * add polaris transformers
+ */
+ private void addPolarisTransformers(TransformOperations operations) {
+
+ // 注入默认配置
+ operations.transform(Constant.CONFIGURATION_CLAZZ_POST_PROCESSOR, ConfigurationPostProcessorTransform.class);
+
+ // 注入bootstrap的bean定义
+ operations.transform(Constant.CONFIGURATION_CLAZZ_PARSER, ConfigurationParserTransform.class);
+
+ // 注入bean定义的调整设置
+ operations.transform(Constant.BEAN_DEFINITION_REGISTRY, RegisterBeanDefinitionTransform.class);
+
+ // 注入JNI定义
+ operations.transform(Constant.SPRING_FACTORIES_LOADER, SpringFactoriesLoaderTransform.class);
+ }
+
+ public static class ConfigurationParserTransform implements TransformCallback {
+
+ @Override
+ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
+ InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
+ InstrumentMethod constructMethod = target.getDeclaredMethod("parse", "java.util.Set");
+ if (constructMethod != null) {
+ constructMethod.addInterceptor(ConfigurationParserInterceptor.class);
+ }
+
+ return target.toBytecode();
+ }
+ }
+
+ public static class ConfigurationPostProcessorTransform implements TransformCallback {
+
+ @Override
+ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
+ InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
+ InstrumentMethod constructMethod = target.getDeclaredMethod("processConfigBeanDefinitions", "org.springframework.beans.factory.support.BeanDefinitionRegistry");
+ if (constructMethod != null) {
+ constructMethod.addInterceptor(ConfigurationPostProcessorInterceptor.class);
+ }
+
+ return target.toBytecode();
+ }
+ }
+
+ public static class RegisterBeanDefinitionTransform implements TransformCallback {
+
+ @Override
+ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
+ InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
+ InstrumentMethod constructMethod = target.getDeclaredMethod("registerBeanDefinition", "java.lang.String", "org.springframework.beans.factory.config.BeanDefinition");
+ if (constructMethod != null) {
+ constructMethod.addInterceptor(RegisterBeanInterceptor.class);
+ }
+
+ return target.toBytecode();
+ }
+ }
+
+ public static class SpringFactoriesLoaderTransform implements TransformCallback {
+
+ @Override
+ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
+ InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
+ InstrumentMethod constructMethod = target.getConstructor("java.lang.ClassLoader", "java.util.Map");
+ if (constructMethod != null) {
+ constructMethod.addInterceptor(SpringFactoriesLoaderInterceptor.class);
+ }
+
+ return target.toBytecode();
+ }
+ }
}
\ No newline at end of file
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
index 9174126e..3b174031 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
@@ -17,17 +17,16 @@
package cn.polarismesh.agent.plugin.spring.cloud.interceptor;
+import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.core.extension.interceptor.Interceptor;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.inject.*;
+import com.tencent.polaris.api.utils.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
public class SpringFactoriesLoaderInterceptor implements Interceptor {
@@ -55,38 +54,33 @@ public SpringFactoriesLoaderInterceptor() {
@SuppressWarnings("unchecked")
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
- if (args[0] == null) {
- return;
+ Map> oldFactories = (Map>) ReflectionUtils.getObjectByFieldName(target, "factories");
+ Map> newFactories = new HashMap<>();
+ for (Map.Entry> entry : oldFactories.entrySet()) {
+ newFactories.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
- ClassLoader classLoader = (ClassLoader) args[0];
- parsedClasses.computeIfAbsent(classLoader, new Function() {
- @Override
- public Boolean apply(ClassLoader classLoader) {
- Map> loadedClasses = (Map>) result;
- for (BeanInjector beanInjector : beanInjectors) {
- LOGGER.info("[PolarisJavaAgent] start to inject JNI definition in module {}", beanInjector.getModule());
- Map> classNames = beanInjector.getClassNameForType();
- if (classNames.isEmpty()) {
- continue;
- }
- for (Map.Entry> entry : classNames.entrySet()) {
- List existsValues = loadedClasses.get(entry.getKey());
- List toAddValues = entry.getValue();
- if (null != existsValues) {
- for (String toAddValue : toAddValues) {
- if (existsValues.contains(toAddValue)) {
- continue;
- }
- existsValues.add(toAddValue);
- }
- } else {
- classNames.put(entry.getKey(), toAddValues);
+ for (BeanInjector beanInjector : beanInjectors) {
+ LOGGER.info("[PolarisJavaAgent] start to inject JNI definition in module {}", beanInjector.getModule());
+ Map> classNames = beanInjector.getClassNameForType();
+ if (CollectionUtils.isEmpty(classNames)) {
+ continue;
+ }
+ for (Map.Entry> entry : classNames.entrySet()) {
+ List existsValues = newFactories.get(entry.getKey());
+ List toAddValues = entry.getValue();
+ if (null != existsValues) {
+ for (String toAddValue : toAddValues) {
+ if (existsValues.contains(toAddValue)) {
+ continue;
}
+ existsValues.add(toAddValue);
}
+ } else {
+ classNames.put(entry.getKey(), toAddValues);
}
- return true;
}
- });
+ }
+ ReflectionUtils.setValueByFieldName(target, "factories", Collections.unmodifiableMap(newFactories));
}
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
index b396bdac..a8fc4900 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
@@ -23,9 +23,26 @@
+
+ org.springframework.boot
+ spring-boot-starter-logging
+ ${spring.boot.version}
+ provided
+
+
+ ch.qos.logback
+ logback-classic
+ provided
+
+
+ ch.qos.logback
+ logback-core
+ provided
+
org.springframework.boot
spring-boot-starter-web
+ provided
org.springframework.boot
@@ -61,10 +78,6 @@
spring-cloud-plugin-common
${project.version}
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
com.tencent.polaris
polaris-agent-core-extension
@@ -153,6 +166,16 @@
+
+ com.tencent.polaris
+ connector-nacos
+
+
+
+ com.tencent.polaris
+ connector-consul
+
+
com.tencent.polaris
connector-composite
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
index ddec44cf..8f0f8a30 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
@@ -21,6 +21,7 @@
import cn.polarismesh.agent.core.extension.interceptor.Interceptor;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.inject.*;
+import com.tencent.polaris.api.utils.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,7 +59,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
for (BeanInjector beanInjector : beanInjectors) {
LOGGER.info("[PolarisJavaAgent] start to inject JNI definition in module {}", beanInjector.getModule());
Map> classNames = beanInjector.getClassNameForType();
- if (classNames.isEmpty()) {
+ if (CollectionUtils.isEmpty(classNames)) {
continue;
}
for (Map.Entry> entry : classNames.entrySet()) {
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
index 5345f013..f6391aee 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
@@ -21,9 +21,25 @@
+
+ org.springframework.boot
+ spring-boot-starter-logging
+ provided
+
+
+ ch.qos.logback
+ logback-classic
+ provided
+
+
+ ch.qos.logback
+ logback-core
+ provided
+
org.springframework.boot
spring-boot-starter-web
+ provided
org.springframework.boot
@@ -66,10 +82,6 @@
spring-cloud-plugin-common
${project.version}
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
com.tencent.polaris
polaris-agent-core-extension
@@ -157,6 +169,16 @@
connector-polaris-grpc
+
+ com.tencent.polaris
+ connector-nacos
+
+
+
+ com.tencent.polaris
+ connector-consul
+
+
com.tencent.polaris
connector-composite
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
index 40b64b9c..0e6979b4 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
@@ -20,6 +20,7 @@
import cn.polarismesh.agent.core.extension.interceptor.Interceptor;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.inject.*;
+import com.tencent.polaris.api.utils.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,11 +64,14 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
@Override
public Boolean apply(ClassLoader classLoader) {
Map> loadedClasses = (Map>) result;
+ if (loadedClasses == null) {
+ loadedClasses = new ConcurrentHashMap<>();
+ }
for (BeanInjector beanInjector : beanInjectors) {
LOGGER.info("[PolarisJavaAgent] start to inject JNI definition in module {}", beanInjector.getModule());
Map> classNames = beanInjector.getClassNameForType();
- if (classNames.isEmpty()) {
+ if (CollectionUtils.isEmpty(classNames)) {
continue;
}
for (Map.Entry> entry : classNames.entrySet()) {
diff --git a/pom.xml b/pom.xml
index d51b4d25..15f1f2a3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
https://github.com/polarismesh/polaris-java-agent
- 1.7.0-RC7
+ 1.7.0-RC8
1.15.5
32.0.1-jre
UTF-8
From 34b448702147ddb406b0e8c49f5bb1b28a2e7917 Mon Sep 17 00:00:00 2001
From: Haotian Zhang <928016560@qq.com>
Date: Tue, 30 Jul 2024 16:32:18 +0800
Subject: [PATCH 3/5] fix:fix log framework conflict.
---
.../quickstart-examples/provider-a/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
index d71e5a15..963fe450 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
@@ -43,6 +43,7 @@
org.springframework.boot
spring-boot-starter-log4j2
+ 2.3.12.RELEASE
From 49de8696971a78171d77b2017bd2797329b1f9e3 Mon Sep 17 00:00:00 2001
From: Haotian Zhang <928016560@qq.com>
Date: Tue, 30 Jul 2024 16:35:55 +0800
Subject: [PATCH 4/5] fix:fix log framework conflict.
---
.../quickstart-examples/provider-a/pom.xml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
index 963fe450..81710f6a 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/pom.xml
@@ -40,6 +40,12 @@
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.17.1
+
+
org.springframework.boot
spring-boot-starter-log4j2
From 4414fd3ad7e34aa317d51649d35e08b92793054d Mon Sep 17 00:00:00 2001
From: Haotian Zhang <928016560@qq.com>
Date: Wed, 31 Jul 2024 11:40:06 +0800
Subject: [PATCH 5/5] fix:fix log framework conflict.
---
.../cloud/interceptor/SpringFactoriesLoaderInterceptor.java | 3 +++
.../cloud/interceptor/SpringFactoriesLoaderInterceptor.java | 3 +++
2 files changed, 6 insertions(+)
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
index 3b174031..326823d1 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
@@ -55,6 +55,9 @@ public SpringFactoriesLoaderInterceptor() {
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
Map> oldFactories = (Map>) ReflectionUtils.getObjectByFieldName(target, "factories");
+ if (CollectionUtils.isEmpty(oldFactories)) {
+ oldFactories = new HashMap<>();
+ }
Map> newFactories = new HashMap<>();
for (Map.Entry> entry : oldFactories.entrySet()) {
newFactories.put(entry.getKey(), new ArrayList<>(entry.getValue()));
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
index 8f0f8a30..5f21c3fd 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java
@@ -51,6 +51,9 @@ public SpringFactoriesLoaderInterceptor() {
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
Map> oldFactories = (Map>) ReflectionUtils.getObjectByFieldName(target, "factories");
+ if (CollectionUtils.isEmpty(oldFactories)) {
+ oldFactories = new HashMap<>();
+ }
Map> newFactories = new HashMap<>();
for (Map.Entry> entry : oldFactories.entrySet()) {
newFactories.put(entry.getKey(), new ArrayList<>(entry.getValue()));