diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml
index 923ec9ee..2add1587 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml
@@ -1,105 +1,99 @@
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.1.8
-
-
- 4.0.0
+ 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.8
+
+
+ 4.0.0
- com.tencent.polaris
- polaris-javaagent-demo-sc-quickstart-2022-consumer
- jar
- 1.7.0
+ com.tencent.polaris
+ polaris-javaagent-demo-sc-quickstart-2022-consumer
+ jar
+ 1.7.0
- 2022-consumer
- Demo Consumer Project For Spring Cloud Alibaba
+ 2022-consumer
+ Demo Consumer Project For Spring Cloud Alibaba
-
-
-
- com.alibaba.cloud
- spring-cloud-alibaba-dependencies
- 2022.0.0.0
- pom
- import
-
+
+
+
+ com.alibaba.cloud
+ spring-cloud-alibaba-dependencies
+ 2022.0.0.0
+ pom
+ import
+
-
- org.springframework.cloud
- spring-cloud-dependencies
- 2022.0.5
- pom
- import
-
-
-
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2022.0.5
+ pom
+ import
+
+
+
-
-
-
- org.springframework.cloud
- spring-cloud-starter-circuitbreaker-resilience4j
-
-
- org.springframework.cloud
- spring-cloud-starter-bootstrap
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
-
- org.springframework.boot
- spring-boot-starter-webflux
-
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-discovery
-
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
-
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
-
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
-
- org.springframework.boot
- spring-boot-starter-actuator
-
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- true
-
-
-
-
- repackage
-
-
-
-
-
-
+
+
+
+ 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/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
index 743bd44e..fffd4b07 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
@@ -1,5 +1,5 @@
server.port=65001
-spring.application.name=service-provider-2022
+spring.application.name=service-provider-2023
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.enabled=true
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
index e2e4dd59..46b9188d 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
@@ -11,7 +11,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-//import org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration;
import org.springframework.core.env.Environment;
import java.lang.reflect.Constructor;
@@ -20,27 +19,81 @@
public class CircuitBreakerBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-circuitbreaker";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-polaris-circuitbreaker";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.circuitbreaker.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris circuitbreaker not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object polarisCircuitBreakerBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerBootstrapConfiguration.class, "polarisCircuitBreakerBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisCircuitBreakerBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisCircuitBreakerBootstrapConfiguration.class).getBeanDefinition());
+ Object polarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerAutoConfiguration.class, "polarisCircuitBreakerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition());
+ if (null != ClassUtils.getClazz("reactor.core.publisher.Mono", Thread.currentThread().getContextClassLoader())
+ && null != ClassUtils.getClazz("reactor.core.publisher.Flux", Thread.currentThread()
+ .getContextClassLoader())) {
+ Object reactivePolarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, ReactivePolarisCircuitBreakerAutoConfiguration.class, "reactivePolarisCircuitBreakerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, reactivePolarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("reactivePolarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ ReactivePolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition());
+ }
+ if (null != ClassUtils.getClazz("feign.Feign", Thread.currentThread().getContextClassLoader())
+ && null != ClassUtils.getClazz("org.springframework.cloud.openfeign.FeignClientFactoryBean", Thread.currentThread()
+ .getContextClassLoader())) {
+ Object polarisCircuitBreakerFeignClientAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerFeignClientAutoConfiguration.class, "polarisCircuitBreakerFeignClientAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerFeignClientAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisCircuitBreakerFeignClientAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisCircuitBreakerFeignClientAutoConfiguration.class).getBeanDefinition());
+ }
+ if (null != ClassUtils.getClazz("org.springframework.web.reactive.DispatcherHandler", Thread.currentThread()
+ .getContextClassLoader())
+ && null != ClassUtils.getClazz("com.tencent.cloud.polaris.circuitbreaker.config.ReactivePolarisCircuitBreakerAutoConfiguration", Thread.currentThread()
+ .getContextClassLoader())
+ && null != ClassUtils.getClazz("org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory", Thread.currentThread()
+ .getContextClassLoader())
+ && null != ClassUtils.getClazz("com.tencent.cloud.polaris.circuitbreaker.ReactivePolarisCircuitBreakerFactory", Thread.currentThread()
+ .getContextClassLoader())
+ && null != ClassUtils.getClazz("org.springframework.cloud.gateway.config.GatewayAutoConfiguration", Thread.currentThread()
+ .getContextClassLoader())) {
+ String property = environment.getProperty("spring.cloud.gateway.enabled");
+ if (Boolean.parseBoolean(property)) {
+ Object gatewayPolarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, GatewayPolarisCircuitBreakerAutoConfiguration.class, "gatewayPolarisCircuitBreakerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, gatewayPolarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("gatewayPolarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ GatewayPolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition());
+ }
+ }
+ Object polarisCircuitBreakerEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerEndpointAutoConfiguration.class, "polarisCircuitBreakerEndpointAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisCircuitBreakerEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisCircuitBreakerEndpointAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisCircuitBreakerEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerEndpointAutoConfiguration.class, "polarisCircuitBreakerEndpointAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisCircuitBreakerEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisCircuitBreakerEndpointAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.circuitbreaker.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
index 2ed6ea6d..7ad7f07e 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
@@ -17,38 +17,39 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.Map;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration;
-import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-import org.springframework.core.io.ClassPathResource;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
public class LoadbalancerBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-polaris-loadbalancer";
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class);
+
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-polaris-loadbalancer";
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisLoadBalancerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoadBalancerAutoConfiguration.class, "polarisLoadBalancerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoadBalancerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisLoadBalancerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisLoadBalancerAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.loadbalancer.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris loadbalancer not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ Object polarisLoadBalancerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoadBalancerAutoConfiguration.class, "polarisLoadBalancerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoadBalancerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisLoadBalancerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisLoadBalancerAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
index 62cc0081..76e6e2a2 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
@@ -17,10 +17,6 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
@@ -30,39 +26,56 @@
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
+
public class LosslessBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-lossless-plugin";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-lossless-plugin";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessPropertiesBootstrapConfiguration.class).getBeanDefinition());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.lossless.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris lossless not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessPropertiesBootstrapConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object losslessAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessAutoConfiguration.class, "losslessAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessAutoConfiguration.class).getBeanDefinition());
- Object losslessPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesAutoConfiguration.class, "losslessPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessPropertiesAutoConfiguration.class).getBeanDefinition());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.lossless.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris lossless not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object losslessPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesAutoConfiguration.class, "losslessPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object losslessAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessAutoConfiguration.class, "losslessAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
index fe1cabd8..42fc15c9 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
@@ -17,48 +17,39 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.metadata.config.MetadataTransferAutoConfiguration;
-import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration;
-import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration;
-import com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-public class MetadataTransferBeanInjector implements BeanInjector {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MetadataTransferBeanInjector.class);
-
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
-
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-metadata-transfer";
- }
-
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- Object metadataTransferAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataTransferAutoConfiguration.class, "metadataTransferAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataTransferAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("metadataTransferAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- MetadataTransferAutoConfiguration.class).getBeanDefinition());
- }
-
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
- }
+public class MetadataTransferBeanInjector implements BeanInjector {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MetadataTransferBeanInjector.class);
+
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-metadata-transfer";
+ }
+
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ Object metadataTransferAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataTransferAutoConfiguration.class, "metadataTransferAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataTransferAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("metadataTransferAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ MetadataTransferAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
index f45c328e..005172fd 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
@@ -23,6 +23,7 @@ public class RateLimitBeanInjector implements BeanInjector {
private static final Logger LOGGER = LoggerFactory.getLogger(RateLimitBeanInjector.class);
private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-ratelimit";
@@ -30,27 +31,39 @@ public String getModule() {
@Override
public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.ratelimit.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris ratelimit not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object polarisRateLimitPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesBootstrapConfiguration.class, "polarisRateLimitPropertiesBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRateLimitPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRateLimitPropertiesBootstrapConfiguration.class).getBeanDefinition());
LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
}
@Override
public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.ratelimit.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris ratelimit not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
Object polarisRateLimitAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitAutoConfiguration.class, "polarisRateLimitAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisRateLimitAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisRateLimitAutoConfiguration.class).getBeanDefinition());
- Object polarisRateLimitRuleEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitRuleEndpointAutoConfiguration.class, "polarisRateLimitRuleEndpointAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitRuleEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRateLimitRuleEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRateLimitRuleEndpointAutoConfiguration.class).getBeanDefinition());
- Object polarisRateLimitPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesBootstrapConfiguration.class, "polarisRateLimitPropertiesBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRateLimitPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRateLimitPropertiesBootstrapConfiguration.class).getBeanDefinition());
Object polarisRateLimitPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesAutoConfiguration.class, "polarisRateLimitPropertiesAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisRateLimitPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisRateLimitPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object polarisRateLimitRuleEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitRuleEndpointAutoConfiguration.class, "polarisRateLimitRuleEndpointAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitRuleEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRateLimitRuleEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRateLimitRuleEndpointAutoConfiguration.class).getBeanDefinition());
LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
}
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
index beba7a91..5d660e80 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
@@ -17,92 +17,91 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
-import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClientConfiguration;
import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration;
-import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
-import com.tencent.polaris.api.config.Configuration;
+import com.tencent.cloud.polaris.discovery.refresh.PolarisRefreshConfiguration;
import com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration;
-import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration;
import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration;
-import com.tencent.cloud.common.metadata.StaticMetadataManager;
-import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties;
-import com.tencent.cloud.polaris.registry.PolarisAutoServiceRegistration;
-import com.tencent.cloud.polaris.registry.PolarisRegistration;
-import com.tencent.cloud.polaris.registry.PolarisServiceRegistry;
-import com.tencent.polaris.client.api.SDKContext;
-import com.tencent.cloud.polaris.discovery.refresh.PolarisRefreshConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.springframework.core.env.Environment;
-public class RegistryBeanInjector implements BeanInjector {
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
- private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class);
+public class RegistryBeanInjector implements BeanInjector {
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class);
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-discovery";
- }
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-polaris-discovery";
+ }
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.discovery.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris discovery not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("discoveryPropertiesBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ DiscoveryPropertiesBootstrapAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisDiscoveryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryAutoConfiguration.class, "polarisDiscoveryAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryAutoConfiguration.class).getBeanDefinition());
- Object polarisDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryClientConfiguration.class, "polarisDiscoveryClientConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryClientConfiguration.class).getBeanDefinition());
- Object polarisReactiveDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisReactiveDiscoveryClientConfiguration.class, "polarisReactiveDiscoveryClientConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisReactiveDiscoveryClientConfiguration,Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisReactiveDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisReactiveDiscoveryClientConfiguration.class).getBeanDefinition());
- Object polarisRefreshConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRefreshConfiguration.class, "polarisRefreshConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRefreshConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRefreshConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRefreshConfiguration.class).getBeanDefinition());
- Object polarisServiceRegistryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisServiceRegistryAutoConfiguration.class, "polarisServiceRegistryAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisServiceRegistryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisServiceRegistryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisServiceRegistryAutoConfiguration.class).getBeanDefinition());
- Object polarisDiscoveryEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryEndpointAutoConfiguration.class, "polarisDiscoveryEndpointAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition());
- Object discoveryPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesAutoConfiguration.class, "discoveryPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("discoveryPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- DiscoveryPropertiesAutoConfiguration.class).getBeanDefinition());
- Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("discoveryPropertiesBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- DiscoveryPropertiesBootstrapAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.discovery.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris discovery not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object discoveryPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesAutoConfiguration.class, "discoveryPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("discoveryPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ DiscoveryPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryAutoConfiguration.class, "polarisDiscoveryAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryClientConfiguration.class, "polarisDiscoveryClientConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryClientConfiguration.class).getBeanDefinition());
+ Object polarisReactiveDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisReactiveDiscoveryClientConfiguration.class, "polarisReactiveDiscoveryClientConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisReactiveDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisReactiveDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisReactiveDiscoveryClientConfiguration.class).getBeanDefinition());
+ Object polarisRefreshConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRefreshConfiguration.class, "polarisRefreshConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRefreshConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRefreshConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRefreshConfiguration.class).getBeanDefinition());
+ Object polarisServiceRegistryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisServiceRegistryAutoConfiguration.class, "polarisServiceRegistryAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisServiceRegistryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisServiceRegistryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisServiceRegistryAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryEndpointAutoConfiguration.class, "polarisDiscoveryEndpointAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
index d5243b97..6da5c81a 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
@@ -17,115 +17,74 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ClassUtils;
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
-import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
-import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerAutoConfiguration;
-import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration;
-import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerFeignClientAutoConfiguration;
-import com.tencent.cloud.polaris.circuitbreaker.config.ReactivePolarisCircuitBreakerAutoConfiguration;
-import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
-import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
import com.tencent.cloud.polaris.router.config.FeignAutoConfiguration;
import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration;
-import com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
import com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration;
-import com.tencent.cloud.rpc.enhancement.webclient.PolarisLoadBalancerClientRequestTransformer;
+import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
+import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
+import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-import org.springframework.core.io.ClassPathResource;
-
-public class RouterBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(RouterBeanInjector.class);
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-router";
- }
-
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+public class RouterBeanInjector implements BeanInjector {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RouterBeanInjector.class);
- @Override
- @SuppressWarnings("unchecked")
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- if (null != ClassUtils.getClazz("feign.RequestInterceptor",
- Thread.currentThread().getContextClassLoader())) {
- Object feignAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, FeignAutoConfiguration.class, "feignAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, feignAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("feignAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- FeignAutoConfiguration.class).getBeanDefinition());
- }
- Object routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RouterAutoConfiguration.class).getBeanDefinition());
- Object polarisNearByRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisNearByRouterProperties.class, "polarisNearByRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisNearByRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisNearByRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisNearByRouterProperties.class).getBeanDefinition());
- Object polarisRuleBasedRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRuleBasedRouterProperties.class, "polarisRuleBasedRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRuleBasedRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRuleBasedRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRuleBasedRouterProperties.class).getBeanDefinition());
- Object routerConfigModifierAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterConfigModifierAutoConfiguration.class, "routerConfigModifierAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerConfigModifierAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("routerConfigModifierAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RouterConfigModifierAutoConfiguration.class).getBeanDefinition());
- Object polarisContractPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractPropertiesAutoConfiguration.class, "polarisContractPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition());
- Object polarisMetadataRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataRouterProperties.class, "polarisMetadataRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisMetadataRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisMetadataRouterProperties.class).getBeanDefinition());
- Object polarisCircuitBreakerBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerBootstrapConfiguration.class, "polarisCircuitBreakerBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisCircuitBreakerBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisCircuitBreakerBootstrapConfiguration.class).getBeanDefinition());
- if (null != ClassUtils.getClazz("reactor.core.publisher.Mono", Thread.currentThread().getContextClassLoader())
- && null != ClassUtils.getClazz("reactor.core.publisher.Flux", Thread.currentThread()
- .getContextClassLoader())) {
- Object reactivePolarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, ReactivePolarisCircuitBreakerAutoConfiguration.class, "reactivePolarisCircuitBreakerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, reactivePolarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("reactivePolarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- ReactivePolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition());
- }
- if (null != ClassUtils.getClazz("feign.Feign", Thread.currentThread().getContextClassLoader())
- && null != ClassUtils.getClazz("org.springframework.cloud.openfeign.FeignClientFactoryBean", Thread.currentThread()
- .getContextClassLoader())) {
- Object polarisCircuitBreakerFeignClientAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerFeignClientAutoConfiguration.class, "polarisCircuitBreakerFeignClientAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerFeignClientAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisCircuitBreakerFeignClientAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisCircuitBreakerFeignClientAutoConfiguration.class).getBeanDefinition());
- }
- Object polarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerAutoConfiguration.class, "polarisCircuitBreakerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition());
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-polaris-router";
+ }
+ @Override
+ @SuppressWarnings("unchecked")
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.router.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris router not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ Object routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RouterAutoConfiguration.class).getBeanDefinition());
+ if (null != ClassUtils.getClazz("feign.RequestInterceptor",
+ Thread.currentThread().getContextClassLoader())) {
+ Object feignAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, FeignAutoConfiguration.class, "feignAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, feignAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("feignAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ FeignAutoConfiguration.class).getBeanDefinition());
+ }
+ Object polarisNearByRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisNearByRouterProperties.class, "polarisNearByRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisNearByRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisNearByRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisNearByRouterProperties.class).getBeanDefinition());
+ Object polarisRuleBasedRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRuleBasedRouterProperties.class, "polarisRuleBasedRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRuleBasedRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRuleBasedRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRuleBasedRouterProperties.class).getBeanDefinition());
+ Object routerConfigModifierAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterConfigModifierAutoConfiguration.class, "routerConfigModifierAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerConfigModifierAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("routerConfigModifierAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RouterConfigModifierAutoConfiguration.class).getBeanDefinition());
+ Object polarisContractPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractPropertiesAutoConfiguration.class, "polarisContractPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object polarisMetadataRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataRouterProperties.class, "polarisMetadataRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisMetadataRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisMetadataRouterProperties.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
index 6061a417..4fb084e4 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
@@ -17,11 +17,6 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import cn.polarismesh.agent.core.common.utils.ClassUtils;
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
@@ -30,48 +25,62 @@
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementBootstrapConfiguration;
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesAutoConfiguration;
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesBootstrapConfiguration;
-import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
+
public class RpcEnhancementBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-rpc-enhancement";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-rpc-enhancement";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.tencent.rpc-enhancement.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris rpc-enhancement not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisStatPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisStatPropertiesBootstrapConfiguration.class).getBeanDefinition());
+ Object rpcEnhancementBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementBootstrapConfiguration.class, "rpcEnhancementBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("rpcEnhancementBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RpcEnhancementBootstrapConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisStatPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisStatPropertiesBootstrapConfiguration.class).getBeanDefinition());
- Object rpcEnhancementBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementBootstrapConfiguration.class, "rpcEnhancementBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("rpcEnhancementBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RpcEnhancementBootstrapConfiguration.class).getBeanDefinition());
- Object polarisStatPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesAutoConfiguration.class, "polarisStatPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisStatPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition());
- Object rpcEnhancementAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementAutoConfiguration.class, "rpcEnhancementAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("rpcEnhancementAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RpcEnhancementAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.tencent.rpc-enhancement.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris rpc-enhancement not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object polarisStatPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesAutoConfiguration.class, "polarisStatPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisStatPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object rpcEnhancementAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementAutoConfiguration.class, "rpcEnhancementAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("rpcEnhancementAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RpcEnhancementAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java
index e0da174d..2c3d8214 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java
@@ -17,142 +17,126 @@
package cn.polarismesh.agent.plugin.spring.cloud.interceptor;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Predicate;
-
import cn.polarismesh.agent.core.common.utils.ClassUtils;
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.common.PropertiesProvider;
-import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.CommonBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.ConfigBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.LoadbalancerBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.LosslessBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.MetadataTransferBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.PolarisContextBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RegistryBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RouterBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RpcEnhancementBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.CircuitBreakerBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RateLimitBeanInjector;
+import cn.polarismesh.agent.plugin.spring.cloud.inject.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
-import org.springframework.core.env.MutablePropertySources;
-import org.springframework.core.env.PropertiesPropertySource;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
public class ConfigurationParserInterceptor implements Interceptor {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationParserInterceptor.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationParserInterceptor.class);
- private final List beanInjectors = new ArrayList<>();
+ private final List beanInjectors = new ArrayList<>();
private boolean judge = false;
- public ConfigurationParserInterceptor() {
- beanInjectors.add(new CircuitBreakerBeanInjector());
- beanInjectors.add(new RateLimitBeanInjector());
- beanInjectors.add(new CommonBeanInjector());
- beanInjectors.add(new MetadataTransferBeanInjector());
- beanInjectors.add(new RegistryBeanInjector());
- beanInjectors.add(new RpcEnhancementBeanInjector());
- beanInjectors.add(new PolarisContextBeanInjector());
- beanInjectors.add(new RouterBeanInjector());
- beanInjectors.add(new LoadbalancerBeanInjector());
- beanInjectors.add(new ConfigBeanInjector());
- beanInjectors.add(new LosslessBeanInjector());
- }
-
-
- private static boolean isMainBeanDefinition(BeanDefinitionHolder beanDefinitionHolder) {
- BeanDefinition beanDefinition = beanDefinitionHolder.getBeanDefinition();
- if (beanDefinition instanceof AnnotatedGenericBeanDefinition) {
- AnnotatedGenericBeanDefinition annotatedBeanDefinition = (AnnotatedGenericBeanDefinition)beanDefinition;
- Class> beanClass = annotatedBeanDefinition.getBeanClass();
- Annotation[] annotations = beanClass.getAnnotations();
- for (Annotation annotation : annotations) {
- Class extends Annotation> aClass = annotation.annotationType();
- if ("org.springframework.boot.autoconfigure.SpringBootApplication".equals(aClass.getCanonicalName())) {
- return true;
- }
- }
- }
- return false;
- }
-
- @Override
- public void after(Object target, Object[] args, Object result, Throwable throwable) {
- Set> candidates = (Set>) args[0];
- BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next();
- if ("bootstrapImportSelectorConfiguration".equals(beanDefinitionHolder.getBeanName())) {
- // bootstrap
- Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
- Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
- Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
- ReflectionUtils.makeAccessible(processConfigurationClass);
-
- BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
- Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
- for (BeanInjector beanInjector : beanInjectors) {
- LOGGER.info("[PolarisJavaAgent] start to inject bootstrap bean definitions in module {}", beanInjector.getModule());
- beanInjector.onBootstrapStartup(target, constructor, processConfigurationClass, registry, environment);
- }
- LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent bootstrap bean definitions");
-
- } else if (isMainBeanDefinition(beanDefinitionHolder)) {
- Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
- Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
- Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
- ReflectionUtils.makeAccessible(processConfigurationClass);
-
- BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
- Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
- for (BeanInjector beanInjector : beanInjectors) {
- if (!(beanInjector instanceof RouterBeanInjector)) {
- LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule());
- beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment);
- }
- }
- LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions");
-
- }
- }
-
- @Override
- public void before(Object target, Object[] args) {
- Set> candidates = (Set>) args[0];
- BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next();
- if (isMainBeanDefinition(beanDefinitionHolder)) {
- Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
- Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
- Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
- ReflectionUtils.makeAccessible(processConfigurationClass);
-
- BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
- Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
- for (BeanInjector beanInjector : beanInjectors) {
- if ((beanInjector instanceof RouterBeanInjector)) {
- LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule());
- beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment);
- }
- }
- LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions");
-
- }
- }
+ public ConfigurationParserInterceptor() {
+ beanInjectors.add(new CommonBeanInjector());
+ beanInjectors.add(new PolarisContextBeanInjector());
+ beanInjectors.add(new MetadataTransferBeanInjector());
+ beanInjectors.add(new RegistryBeanInjector());
+ beanInjectors.add(new ConfigBeanInjector());
+ beanInjectors.add(new RpcEnhancementBeanInjector());
+ beanInjectors.add(new LosslessBeanInjector());
+ beanInjectors.add(new LoadbalancerBeanInjector());
+ beanInjectors.add(new RouterBeanInjector());
+ beanInjectors.add(new CircuitBreakerBeanInjector());
+ beanInjectors.add(new RateLimitBeanInjector());
+ }
+
+
+ private static boolean isMainBeanDefinition(BeanDefinitionHolder beanDefinitionHolder) {
+ BeanDefinition beanDefinition = beanDefinitionHolder.getBeanDefinition();
+ if (beanDefinition instanceof AnnotatedGenericBeanDefinition) {
+ AnnotatedGenericBeanDefinition annotatedBeanDefinition = (AnnotatedGenericBeanDefinition) beanDefinition;
+ Class> beanClass = annotatedBeanDefinition.getBeanClass();
+ Annotation[] annotations = beanClass.getAnnotations();
+ for (Annotation annotation : annotations) {
+ Class extends Annotation> aClass = annotation.annotationType();
+ if ("org.springframework.boot.autoconfigure.SpringBootApplication".equals(aClass.getCanonicalName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void after(Object target, Object[] args, Object result, Throwable throwable) {
+ Set> candidates = (Set>) args[0];
+ BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next();
+ if ("bootstrapImportSelectorConfiguration".equals(beanDefinitionHolder.getBeanName())) {
+ // bootstrap
+ Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
+ Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
+ Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
+ ReflectionUtils.makeAccessible(processConfigurationClass);
+
+ BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
+ Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
+ for (BeanInjector beanInjector : beanInjectors) {
+ LOGGER.info("[PolarisJavaAgent] start to inject bootstrap bean definitions in module {}", beanInjector.getModule());
+ beanInjector.onBootstrapStartup(target, constructor, processConfigurationClass, registry, environment);
+ }
+ LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent bootstrap bean definitions");
+
+ } else if (isMainBeanDefinition(beanDefinitionHolder)) {
+ Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
+ Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
+ Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
+ ReflectionUtils.makeAccessible(processConfigurationClass);
+
+ BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
+ Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
+ for (BeanInjector beanInjector : beanInjectors) {
+ if (!(beanInjector instanceof RouterBeanInjector)) {
+ LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule());
+ beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment);
+ }
+ }
+ LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions");
+
+ }
+ }
+
+ @Override
+ public void before(Object target, Object[] args) {
+ Set> candidates = (Set>) args[0];
+ BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next();
+ if (isMainBeanDefinition(beanDefinitionHolder)) {
+ Class> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
+ Constructor> constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class);
+ Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class);
+ ReflectionUtils.makeAccessible(processConfigurationClass);
+
+ BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
+ Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
+ for (BeanInjector beanInjector : beanInjectors) {
+ if ((beanInjector instanceof RouterBeanInjector)) {
+ LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule());
+ beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment);
+ }
+ }
+ LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions");
+
+ }
+ }
}
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 79f34908..9174126e 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,81 +17,76 @@
package cn.polarismesh.agent.plugin.spring.cloud.interceptor;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
-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.CommonBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.ConfigBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.LoadbalancerBeanInjector;
-//import cn.polarismesh.agent.plugin.spring.cloud.inject.LosslessBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.MetadataTransferBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.PolarisContextBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RegistryBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RouterBeanInjector;
-import cn.polarismesh.agent.plugin.spring.cloud.inject.RpcEnhancementBeanInjector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class SpringFactoriesLoaderInterceptor implements Interceptor {
- private static final Logger LOGGER = LoggerFactory.getLogger(SpringFactoriesLoaderInterceptor.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(SpringFactoriesLoaderInterceptor.class);
- private final List beanInjectors = new ArrayList<>();
+ private final List beanInjectors = new ArrayList<>();
- private final Map parsedClasses = new ConcurrentHashMap<>();
+ private final Map parsedClasses = new ConcurrentHashMap<>();
- public SpringFactoriesLoaderInterceptor() {
- beanInjectors.add(new RegistryBeanInjector());
- beanInjectors.add(new RpcEnhancementBeanInjector());
- beanInjectors.add(new PolarisContextBeanInjector());
- beanInjectors.add(new ConfigBeanInjector());
- beanInjectors.add(new RouterBeanInjector());
- beanInjectors.add(new CommonBeanInjector());
- beanInjectors.add(new MetadataTransferBeanInjector());
- beanInjectors.add(new LoadbalancerBeanInjector());
- }
+ public SpringFactoriesLoaderInterceptor() {
+ beanInjectors.add(new CommonBeanInjector());
+ beanInjectors.add(new PolarisContextBeanInjector());
+ beanInjectors.add(new MetadataTransferBeanInjector());
+ beanInjectors.add(new RegistryBeanInjector());
+ beanInjectors.add(new ConfigBeanInjector());
+ beanInjectors.add(new RpcEnhancementBeanInjector());
+ beanInjectors.add(new LosslessBeanInjector());
+ beanInjectors.add(new LoadbalancerBeanInjector());
+ beanInjectors.add(new RouterBeanInjector());
+ beanInjectors.add(new CircuitBreakerBeanInjector());
+ beanInjectors.add(new RateLimitBeanInjector());
+ }
- @SuppressWarnings("unchecked")
- @Override
- public void after(Object target, Object[] args, Object result, Throwable throwable) {
- if (args[0] == null) {
- return;
- }
- ClassLoader classLoader = (ClassLoader)args[0];
- parsedClasses.computeIfAbsent(classLoader, new Function() {
- @Override
- public Boolean apply(ClassLoader classLoader) {
- Map> loadedClasses = (Map>) result;
+ @SuppressWarnings("unchecked")
+ @Override
+ public void after(Object target, Object[] args, Object result, Throwable throwable) {
+ if (args[0] == null) {
+ return;
+ }
+ 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);
- }
- }
- }
- return true;
- }
- });
- }
+ 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);
+ }
+ }
+ }
+ return true;
+ }
+ });
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
index 2ed6ea6d..7ad7f07e 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
@@ -17,38 +17,39 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.Map;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration;
-import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-import org.springframework.core.io.ClassPathResource;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
public class LoadbalancerBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-polaris-loadbalancer";
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class);
+
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-polaris-loadbalancer";
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisLoadBalancerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoadBalancerAutoConfiguration.class, "polarisLoadBalancerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoadBalancerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisLoadBalancerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisLoadBalancerAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.loadbalancer.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris loadbalancer not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ Object polarisLoadBalancerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoadBalancerAutoConfiguration.class, "polarisLoadBalancerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoadBalancerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisLoadBalancerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisLoadBalancerAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
index 2d487518..76e6e2a2 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
@@ -17,10 +17,6 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
@@ -30,41 +26,56 @@
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
+
public class LosslessBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-lossless-plugin";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-lossless-plugin";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessPropertiesBootstrapConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.lossless.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris lossless not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessPropertiesBootstrapConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object losslessPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesAutoConfiguration.class, "losslessPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessPropertiesAutoConfiguration.class).getBeanDefinition());
- Object losslessAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessAutoConfiguration.class, "losslessAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("losslessAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- LosslessAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.lossless.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris lossless not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object losslessPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesAutoConfiguration.class, "losslessPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object losslessAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessAutoConfiguration.class, "losslessAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("losslessAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ LosslessAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
index c6ee9bfa..a124dcfa 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
@@ -17,48 +17,39 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.metadata.config.MetadataTransferAutoConfiguration;
-import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration;
-import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration;
-import com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-public class MetadataTransferBeanInjector implements BeanInjector {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MetadataTransferBeanInjector.class);
-
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
-
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-metadata-transfer";
- }
-
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- Object metadataTransferAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataTransferAutoConfiguration.class, "metadataTransferAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataTransferAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("metadataTransferAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- MetadataTransferAutoConfiguration.class).getBeanDefinition());
- }
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+public class MetadataTransferBeanInjector implements BeanInjector {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MetadataTransferBeanInjector.class);
+
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-metadata-transfer";
+ }
+
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ Object metadataTransferAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataTransferAutoConfiguration.class, "metadataTransferAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataTransferAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("metadataTransferAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ MetadataTransferAutoConfiguration.class).getBeanDefinition());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
index 0a9ed910..fbe9d444 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
@@ -17,90 +17,90 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
-import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClientConfiguration;
import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration;
-import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
-import com.tencent.polaris.api.config.Configuration;
+import com.tencent.cloud.polaris.discovery.refresh.PolarisRefreshConfiguration;
import com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration;
-import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration;
import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration;
-import com.tencent.cloud.common.metadata.StaticMetadataManager;
-import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties;
-import com.tencent.cloud.polaris.registry.PolarisAutoServiceRegistration;
-import com.tencent.cloud.polaris.registry.PolarisRegistration;
-import com.tencent.cloud.polaris.registry.PolarisServiceRegistry;
-import com.tencent.polaris.client.api.SDKContext;
-import com.tencent.cloud.polaris.discovery.refresh.PolarisRefreshConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.springframework.core.env.Environment;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
+
public class RegistryBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-discovery";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-polaris-discovery";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.discovery.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris discovery not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("discoveryPropertiesBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ DiscoveryPropertiesBootstrapAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisDiscoveryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryAutoConfiguration.class, "polarisDiscoveryAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryAutoConfiguration.class).getBeanDefinition());
- Object polarisDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryClientConfiguration.class, "polarisDiscoveryClientConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryClientConfiguration.class).getBeanDefinition());
- Object polarisReactiveDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisReactiveDiscoveryClientConfiguration.class, "polarisReactiveDiscoveryClientConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisReactiveDiscoveryClientConfiguration,Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisReactiveDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisReactiveDiscoveryClientConfiguration.class).getBeanDefinition());
- Object polarisRefreshConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRefreshConfiguration.class, "polarisRefreshConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRefreshConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRefreshConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRefreshConfiguration.class).getBeanDefinition());
- Object polarisServiceRegistryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisServiceRegistryAutoConfiguration.class, "polarisServiceRegistryAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisServiceRegistryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisServiceRegistryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisServiceRegistryAutoConfiguration.class).getBeanDefinition());
- Object polarisDiscoveryEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryEndpointAutoConfiguration.class, "polarisDiscoveryEndpointAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition());
- Object discoveryPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesAutoConfiguration.class, "discoveryPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("discoveryPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- DiscoveryPropertiesAutoConfiguration.class).getBeanDefinition());
- Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("discoveryPropertiesBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- DiscoveryPropertiesBootstrapAutoConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.discovery.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris discovery not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object discoveryPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesAutoConfiguration.class, "discoveryPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("discoveryPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ DiscoveryPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryAutoConfiguration.class, "polarisDiscoveryAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryClientConfiguration.class, "polarisDiscoveryClientConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryClientConfiguration.class).getBeanDefinition());
+ Object polarisReactiveDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisReactiveDiscoveryClientConfiguration.class, "polarisReactiveDiscoveryClientConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisReactiveDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisReactiveDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisReactiveDiscoveryClientConfiguration.class).getBeanDefinition());
+ Object polarisRefreshConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRefreshConfiguration.class, "polarisRefreshConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRefreshConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRefreshConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRefreshConfiguration.class).getBeanDefinition());
+ Object polarisServiceRegistryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisServiceRegistryAutoConfiguration.class, "polarisServiceRegistryAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisServiceRegistryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisServiceRegistryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisServiceRegistryAutoConfiguration.class).getBeanDefinition());
+ Object polarisDiscoveryEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryEndpointAutoConfiguration.class, "polarisDiscoveryEndpointAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
\ No newline at end of file
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
index e8d0c87b..70d30293 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
@@ -17,85 +17,74 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import cn.polarismesh.agent.core.common.utils.ClassUtils;
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
-import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
-import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
import com.tencent.cloud.polaris.router.config.FeignAutoConfiguration;
import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration;
-import com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration;
-import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
import com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration;
-import com.tencent.cloud.rpc.enhancement.webclient.PolarisLoadBalancerClientRequestTransformer;
+import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
+import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
+import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
-import org.springframework.core.io.ClassPathResource;
-
-public class RouterBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(RouterBeanInjector.class);
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-router";
- }
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+public class RouterBeanInjector implements BeanInjector {
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(RouterBeanInjector.class);
+ @Override
+ public String getModule() {
+ return "spring-cloud-starter-tencent-polaris-router";
+ }
- @Override
- @SuppressWarnings("unchecked")
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- if (null != ClassUtils.getClazz("feign.RequestInterceptor",
- Thread.currentThread().getContextClassLoader())) {
- Object feignAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, FeignAutoConfiguration.class, "feignAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, feignAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("feignAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- FeignAutoConfiguration.class).getBeanDefinition());
- }
- Object routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RouterAutoConfiguration.class).getBeanDefinition());
- Object polarisNearByRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisNearByRouterProperties.class, "polarisNearByRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisNearByRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisNearByRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisNearByRouterProperties.class).getBeanDefinition());
- Object polarisMetadataRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataRouterProperties.class, "polarisMetadataRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisMetadataRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisMetadataRouterProperties.class).getBeanDefinition());
- Object polarisRuleBasedRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRuleBasedRouterProperties.class, "polarisRuleBasedRouterProperties");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRuleBasedRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisRuleBasedRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisRuleBasedRouterProperties.class).getBeanDefinition());
- Object routerConfigModifierAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterConfigModifierAutoConfiguration.class, "routerConfigModifierAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerConfigModifierAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("routerConfigModifierAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RouterConfigModifierAutoConfiguration.class).getBeanDefinition());
- Object polarisContractPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractPropertiesAutoConfiguration.class, "polarisContractPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition());
- }
+ @Override
+ @SuppressWarnings("unchecked")
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.polaris.router.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris router not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ Object routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RouterAutoConfiguration.class).getBeanDefinition());
+ if (null != ClassUtils.getClazz("feign.RequestInterceptor",
+ Thread.currentThread().getContextClassLoader())) {
+ Object feignAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, FeignAutoConfiguration.class, "feignAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, feignAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("feignAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ FeignAutoConfiguration.class).getBeanDefinition());
+ }
+ Object polarisNearByRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisNearByRouterProperties.class, "polarisNearByRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisNearByRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisNearByRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisNearByRouterProperties.class).getBeanDefinition());
+ Object polarisMetadataRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataRouterProperties.class, "polarisMetadataRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisMetadataRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisMetadataRouterProperties.class).getBeanDefinition());
+ Object polarisRuleBasedRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRuleBasedRouterProperties.class, "polarisRuleBasedRouterProperties");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRuleBasedRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisRuleBasedRouterProperties", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisRuleBasedRouterProperties.class).getBeanDefinition());
+ Object routerConfigModifierAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterConfigModifierAutoConfiguration.class, "routerConfigModifierAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerConfigModifierAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("routerConfigModifierAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RouterConfigModifierAutoConfiguration.class).getBeanDefinition());
+ Object polarisContractPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractPropertiesAutoConfiguration.class, "polarisContractPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
index 73a487d1..4fb084e4 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
@@ -17,11 +17,6 @@
package cn.polarismesh.agent.plugin.spring.cloud.inject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import cn.polarismesh.agent.core.common.utils.ClassUtils;
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.common.Constant;
@@ -32,45 +27,60 @@
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesBootstrapConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
+
public class RpcEnhancementBeanInjector implements BeanInjector {
- private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class);
- private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
- @Override
- public String getModule() {
- return "spring-cloud-tencent-rpc-enhancement";
- }
+ @Override
+ public String getModule() {
+ return "spring-cloud-tencent-rpc-enhancement";
+ }
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
- }
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.tencent.rpc-enhancement.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris rpc-enhancement not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
+ Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisStatPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisStatPropertiesBootstrapConfiguration.class).getBeanDefinition());
+ Object rpcEnhancementBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementBootstrapConfiguration.class, "rpcEnhancementBootstrapConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("rpcEnhancementBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RpcEnhancementBootstrapConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule());
+ }
- @Override
- public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
- Object polarisStatPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesAutoConfiguration.class, "polarisStatPropertiesAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisStatPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition());
- Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisStatPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisStatPropertiesBootstrapConfiguration.class).getBeanDefinition());
- Object rpcEnhancementAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementAutoConfiguration.class, "rpcEnhancementAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("rpcEnhancementAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RpcEnhancementAutoConfiguration.class).getBeanDefinition());
- Object rpcEnhancementBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementBootstrapConfiguration.class, "rpcEnhancementBootstrapConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("rpcEnhancementBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- RpcEnhancementBootstrapConfiguration.class).getBeanDefinition());
- LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
+ @Override
+ public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment) && Utils.checkKeyEnabled(environment, "spring.cloud.tencent.rpc-enhancement.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris rpc-enhancement not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
+ Object polarisStatPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesAutoConfiguration.class, "polarisStatPropertiesAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisStatPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition());
+ Object rpcEnhancementAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementAutoConfiguration.class, "rpcEnhancementAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("rpcEnhancementAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ RpcEnhancementAutoConfiguration.class).getBeanDefinition());
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
+ }
}
diff --git a/pom.xml b/pom.xml
index 8239a827..d51b4d25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
https://github.com/polarismesh/polaris-java-agent
- 1.7.0-RC6
+ 1.7.0-RC7
1.15.5
32.0.1-jre
UTF-8