diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/pom.xml
index 60431d36..69178afb 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/pom.xml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/pom.xml
@@ -48,10 +48,6 @@
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-nacos-config
-
org.springframework.cloud
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/src/main/resources/application.properties
index d49c6280..0197ebf6 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-a/src/main/resources/application.properties
@@ -1,10 +1,8 @@
server.port=65203
spring.application.name=service-a-hoxton
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.enabled=true
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
-spring.cloud.nacos.config.serverAddr=127.0.0.1:8848
spring.cloud.nacos.username='nacos'
spring.cloud.nacos.password='nacos'
management.endpoint.health.show-details=always
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/bootstrap.properties
similarity index 80%
rename from polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/application.properties
rename to polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/bootstrap.properties
index c9affe8c..54a77d36 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-b/src/main/resources/bootstrap.properties
@@ -1,9 +1,9 @@
server.port=65202
spring.application.name=service-b-hoxton
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.enabled=true
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
+spring.cloud.nacos.config.enabled=true
spring.cloud.nacos.config.serverAddr=127.0.0.1:8848
spring.cloud.nacos.username='nacos'
spring.cloud.nacos.password='nacos'
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/application.properties
index e7bd9c13..1913c577 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/application.properties
@@ -1,11 +1,6 @@
server.port=65201
-spring.application.name=service-c-hoxton
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.enabled=true
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
-spring.cloud.nacos.config.serverAddr=127.0.0.1:8848
-spring.cloud.nacos.username='nacos'
-spring.cloud.nacos.password='nacos'
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include='*'
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/bootstrap.properties
new file mode 100644
index 00000000..2d1dace8
--- /dev/null
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-c/src/main/resources/bootstrap.properties
@@ -0,0 +1,36 @@
+spring.application.name=service-c-hoxton
+spring.cloud.nacos.config.server-addr=127.0.0.1:8848
+
+#nacos certification information
+spring.cloud.nacos.username=nacos
+spring.cloud.nacos.password=nacos
+
+## nacos-namespace cannot user 'public',cause by 'public' has special handing inside.
+#spring.cloud.nacos.config.namespace=public
+
+## you can specify a custom name if you don't want to use the application name.
+#spring.cloud.nacos.config.name=test-aaa
+#spring.cloud.nacos.config.file-extension=yaml
+
+## not recommended.
+#spring.cloud.nacos.config.refreshable-dataids=common.properties
+## not recommended.
+#spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties
+
+## recommended.
+spring.cloud.nacos.config.shared-configs[0].data-id=data-source.yaml
+spring.cloud.nacos.config.shared-configs[0].refresh=true
+## the default value is 'DEFAULT_GROUP' , if not specified.
+#spring.cloud.nacos.config.shared-configs[0].group=GROUP_APP1
+
+## not recommended.
+#spring.cloud.nacos.config.ext-config[0]=ext.properties
+## recommended.
+spring.cloud.nacos.config.extension-configs[0].data-id=ext-data-source.yaml
+spring.cloud.nacos.config.extension-configs[0].refresh=true
+
+# the setting of reading config log print on stdout
+logging.level.com.alibaba.cloud.nacos.client=debug
+
+
+spring.cloud.nacos.config.refresh-enabled=true
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/application.properties
index 9bb519a1..27a27d6b 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/application.properties
@@ -1,10 +1,3 @@
-server.port=65200
-
-spring.application.name=sc-gateway-hoxton
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.enabled=true
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
-spring.cloud.nacos.config.serverAddr=127.0.0.1:8848
-spring.cloud.nacos.username='nacos'
-spring.cloud.nacos.password='nacos'
spring.cloud.gateway.discovery.locator.enabled=true
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/bootstrap.properties
new file mode 100644
index 00000000..7451f8ac
--- /dev/null
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/gray-release-examples/service-gateway/src/main/resources/bootstrap.properties
@@ -0,0 +1,7 @@
+server.port=65200
+
+spring.application.name=sc-gateway-hoxton
+spring.cloud.nacos.config.enabled=true
+spring.cloud.nacos.config.serverAddr=127.0.0.1:8848
+spring.cloud.nacos.username='nacos'
+spring.cloud.nacos.password='nacos'
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/application.properties
index 64337162..4941df69 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/application.properties
@@ -1,11 +1,5 @@
-#server.port=65001
-#spring.application.name=service-provider-hoxton
-#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-#spring.cloud.nacos.discovery.enabled=false
-#spring.cloud.nacos.config.enabled=false
-#spring.cloud.gateway.discovery.locator.enabled=false
-#spring.cloud.nacos.username=nacos
-#spring.cloud.nacos.password=nacos
-#
-#management.endpoints.web.exposure.include=*
-#management.endpoint.health.show-details=always
\ No newline at end of file
+spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
+spring.cloud.nacos.discovery.enabled=true
+
+management.endpoints.web.exposure.include=*
+management.endpoint.health.show-details=always
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
index c1b8caea..53c1d73d 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider/src/main/resources/bootstrap.properties
@@ -1,11 +1,6 @@
server.port=65001
spring.application.name=service-provider-hoxton
-spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.discovery.enabled=false
-spring.cloud.nacos.config.enabled=false
-spring.cloud.gateway.discovery.locator.enabled=false
+spring.cloud.nacos.config.server-addr=127.0.0.1:8848
+spring.cloud.nacos.config.enabled=true
spring.cloud.nacos.username=nacos
-spring.cloud.nacos.password=nacos
-
-management.endpoints.web.exposure.include=*
-management.endpoint.health.show-details=always
\ No newline at end of file
+spring.cloud.nacos.password=nacos
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/scg/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties
similarity index 100%
rename from polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/scg/src/main/resources/application.properties
rename to polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
index baf0d987..d2e33564 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java
@@ -2,79 +2,110 @@
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;
+import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.polaris.circuitbreaker.config.*;
import com.tencent.cloud.polaris.circuitbreaker.endpoint.PolarisCircuitBreakerEndpointAutoConfiguration;
+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.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration;
import org.springframework.core.env.Environment;
-public class CircuitBreakerBeanInjector implements BeanInjector {
- @Override
- public String getModule() {
- return "spring-cloud-starter-tencent-polaris-circuitbreaker";
- }
+public class CircuitBreakerBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
+ @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) {
- 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("org.springframework.cloud.openfeign.Targeter",
- Thread.currentThread().getContextClassLoader())) {
- String property = environment.getProperty("feign.hystrix.enabled");
- if (Boolean.parseBoolean(property)) {
- Object polarisFeignCircuitBreakerTargeterAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisFeignCircuitBreakerTargeterAutoConfiguration.class, "polarisFeignCircuitBreakerTargeterAutoConfiguration");
- ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisFeignCircuitBreakerTargeterAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
- registry.registerBeanDefinition("polarisFeignCircuitBreakerTargeterAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
- PolarisFeignCircuitBreakerTargeterAutoConfiguration.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.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());
+ if (null != ClassUtils.getClazz("org.springframework.cloud.openfeign.Targeter",
+ Thread.currentThread().getContextClassLoader())) {
+ String property = environment.getProperty("feign.hystrix.enabled");
+ if (Boolean.parseBoolean(property)) {
+ Object polarisFeignCircuitBreakerTargeterAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisFeignCircuitBreakerTargeterAutoConfiguration.class, "polarisFeignCircuitBreakerTargeterAutoConfiguration");
+ ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisFeignCircuitBreakerTargeterAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
+ registry.registerBeanDefinition("polarisFeignCircuitBreakerTargeterAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
+ PolarisFeignCircuitBreakerTargeterAutoConfiguration.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 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());
- }
+ @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);
+ }
+ 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 application bean definitions for module {}", getModule());
+ }
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java
index b717a404..4c471b1b 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java
@@ -23,27 +23,32 @@
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.MetadataAutoConfiguration;
import com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
+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 CommonBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonBeanInjector.class);
+
@Override
public String getModule() {
return "spring-cloud-tencent-commons";
}
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
-
- }
-
@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 applicationContextAwareUtils = ReflectionUtils.invokeConstructor(configClassCreator, ApplicationContextAwareUtils.class, "applicationContextAwareUtils");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, applicationContextAwareUtils, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("applicationContextAwareUtils", BeanDefinitionBuilder.genericBeanDefinition(
@@ -56,5 +61,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisMetadataEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisMetadataEndpointAutoConfiguration.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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java
index 59cda9f6..2480058a 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java
@@ -19,19 +19,28 @@
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.polaris.config.PolarisConfigAutoConfiguration;
import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.config.endpoint.PolarisConfigEndpointAutoConfiguration;
+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 ConfigBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-config";
@@ -39,14 +48,27 @@ 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.config.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris config not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
Object polarisConfigBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigBootstrapAutoConfiguration.class, "polarisConfigBootstrapAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisConfigBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisConfigBootstrapAutoConfiguration.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.config.enabled"))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris config not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
Object polarisConfigAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigAutoConfiguration.class, "polarisConfigAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisConfigAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
@@ -55,5 +77,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisConfigEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisConfigEndpointAutoConfiguration.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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
index bdebf8bf..2f70f39c 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java
@@ -23,28 +23,33 @@
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.config.PolarisLoadBalancerAutoConfiguration;
+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 LoadbalancerBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class);
@Override
public String getModule() {
return "spring-cloud-tencent-polaris-loadbalancer";
}
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
-
- }
-
@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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
index b27d5688..109533f2 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java
@@ -19,19 +19,28 @@
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.plugin.lossless.config.LosslessAutoConfiguration;
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesAutoConfiguration;
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;
public class LosslessBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-tencent-lossless-plugin";
@@ -39,14 +48,27 @@ 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.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) {
+ 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(
@@ -55,5 +77,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
index 26252c99..5115e255 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
@@ -23,7 +23,10 @@
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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -31,22 +34,24 @@
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 onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
-
- }
-
@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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java
index 892c0b9e..8a7f3e2f 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java
@@ -23,20 +23,29 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+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.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.context.config.PolarisContextBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.context.config.PolarisContextPostConfiguration;
import com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener;
+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 PolarisContextBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PolarisContextBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-tencent-polaris-context";
@@ -52,17 +61,28 @@ public Map> getClassNameForType() {
@Override
public void onBootstrapStartup(Object configurationParser,
Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+ if (!(Utils.checkPolarisEnabled(environment))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris not enabled, skip inject bootstrap bean definitions for module {}", getModule());
+ return;
+ }
+ bootstrapLoaded.set(true);
Object polarisContextBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContextBootstrapAutoConfiguration.class, "polarisContextBootstrapAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisContextBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisContextBootstrapAutoConfiguration.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))) {
+ LOGGER.warn("[PolarisJavaAgent] polaris not enabled, skip inject application bean definitions for module {}", getModule());
+ return;
+ }
+ if (!bootstrapLoaded.get()) {
+ onBootstrapStartup(configurationParser, configClassCreator, processConfigurationClass, registry, environment);
+ }
Object polarisContextAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContextAutoConfiguration.class, "polarisContextAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisContextAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
@@ -71,5 +91,6 @@ public void onApplicationStartup(Object configurationParser,
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextPostConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisContextPostConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisContextPostConfiguration.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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
index ad46e3ba..8e46520a 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java
@@ -2,20 +2,28 @@
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.polaris.ratelimit.config.PolarisRateLimitAutoConfiguration;
import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesBootstrapConfiguration;
import com.tencent.cloud.polaris.ratelimit.endpoint.PolarisRateLimitRuleEndpointAutoConfiguration;
+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 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";
@@ -23,14 +31,27 @@ 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(
@@ -43,5 +64,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
index 4ac870e8..ddb8cfb5 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java
@@ -19,22 +19,31 @@
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.polaris.DiscoveryPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration;
import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration;
import com.tencent.cloud.polaris.ribbon.PolarisDiscoveryRibbonAutoConfiguration;
+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 RegistryBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-discovery";
@@ -42,14 +51,27 @@ 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.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) {
+ 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(
@@ -70,5 +92,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
index ceebc757..e4dc9cf4 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java
@@ -25,9 +25,12 @@
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.router.config.FeignAutoConfiguration;
import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration;
import com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -35,19 +38,20 @@
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";
}
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
-
- }
-
@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(
@@ -80,5 +84,6 @@ public void onApplicationStartup(Object configurationParser, Constructor> conf
if (null != targetConfigClass) {
configurationClasses.put(targetConfigClass, targetConfigClass);
}
+ LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
}
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
index 8463ba1c..dc4d44f0 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java
@@ -19,21 +19,30 @@
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;
+import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration;
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 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 RpcEnhancementBeanInjector implements BeanInjector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class);
+
+ private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false);
+
@Override
public String getModule() {
return "spring-cloud-tencent-rpc-enhancement";
@@ -41,25 +50,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.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(
- PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition());
+ 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(
- 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());
+ 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-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java
index 0f116f23..b444ed27 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java
@@ -22,6 +22,7 @@
import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.core.extension.interceptor.Interceptor;
import cn.polarismesh.agent.plugin.spring.cloud.common.PropertiesProvider;
+import cn.polarismesh.agent.plugin.spring.cloud.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,6 +36,10 @@ public class ConfigurationPostProcessorInterceptor implements Interceptor {
@Override
public void before(Object target, Object[] args) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) ReflectionUtils.getObjectByFieldName(target, "environment");
+ if (!Utils.checkSpringApplicationNameExists(environment)) {
+ LOGGER.warn("[PolarisJavaAgent] skip inject polaris java agent configuration for no spring application name");
+ return;
+ }
List propertySources = PropertiesProvider.loadPropertiesSource();
MutablePropertySources mutablePropertySources = environment.getPropertySources();
if (mutablePropertySources.contains(propertySources.get(0).getName())) {
@@ -42,7 +47,7 @@ public void before(Object target, Object[] args) {
}
for (PropertiesPropertySource propertiesPropertySource : propertySources) {
LOGGER.info("[PolarisJavaAgent] start to add propertiesPropertySource {}", propertiesPropertySource.getName());
- environment.getPropertySources().addFirst(propertiesPropertySource);
+ environment.getPropertySources().addLast(propertiesPropertySource);
}
LOGGER.info("[PolarisJavaAgent] successfully injected agent properties into environment, size is " + propertySources.size());
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/resources/default-plugin.conf b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/resources/default-plugin.conf
index bfcf6a63..f37d0470 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/resources/default-plugin.conf
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/resources/default-plugin.conf
@@ -1,5 +1,4 @@
# 配置北极星服务端地址
-spring.cloud.polaris.address=grpc\://127.0.0.1\:8091
spring.cloud.polaris.enabled=true
# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力
@@ -11,21 +10,19 @@ spring.cloud.polaris.discovery.enabled=true
spring.cloud.polaris.discovery.register=true
# 是否启用北极星的 LoadBalancer
-spring.cloud.polaris.loadbalancer.enabled=true
-#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS
-#spring.cloud.polaris.loadbalancer.strategy=random
+spring.cloud.polaris.loadbalancer.enabled=false
# 是否启用北极星服务路由能力
-spring.cloud.polaris.router.enabled=true
+spring.cloud.polaris.router.enabled=false
# 是否启用北极星的自定义路由能力
-spring.cloud.polaris.router.rule-router.enabled=true
+spring.cloud.polaris.router.rule-router.enabled=false
# 是否启用北极星的元数据路由能力
-spring.cloud.polaris.router.metadata-router.enabled=true
+spring.cloud.polaris.router.metadata-router.enabled=false
# 是否启用北极星的就近路由能力
-spring.cloud.polaris.router.nearby-router.enabled=true
+spring.cloud.polaris.router.nearby-router.enabled=false
# 是否启用北极星的服务限流能力
-spring.cloud.polaris.ratelimit.enabled=true
+spring.cloud.polaris.ratelimit.enabled=false
# 设置触发限流时的提示信息
# spring.cloud.polaris.ratelimit.rejectRequestTips=""
# 设置触发限流时的响应码
@@ -34,23 +31,29 @@ spring.cloud.polaris.ratelimit.rejectHttpCode=429
spring.cloud.polaris.ratelimit.maxQueuingTime=1000
# 是否启用北极星的服务熔断能力
-spring.cloud.polaris.circuitbreaker.enabled=true
+spring.cloud.polaris.circuitbreaker.enabled=false
## RPC 调用增强
-spring.cloud.tencent.rpc-enhancement.enabled=true
+spring.cloud.tencent.rpc-enhancement.enabled=false
+
# 开启 RPC 调用结果上报
-spring.cloud.tencent.rpc-enhancement.reporter.enabled=true
+spring.cloud.tencent.rpc-enhancement.reporter.enabled=false
# 配置北极星监控指标上报
-spring.cloud.polaris.stat.enabled=true
+spring.cloud.polaris.stat.enabled=false
# 指标上报监听端口
spring.cloud.polaris.stat.port=0
# 指标上报暴露的 http path
spring.cloud.polaris.stat.path=/metrics
-## 启用北极星配置中心能力
+# 启用北极星配置中心能力
spring.cloud.polaris.config.enabled=true
# 是否开启配置监听刷新
spring.cloud.polaris.config.auto-refresh=true
+# 启用优雅上下线功能
+spring.cloud.polaris.lossless.enabled=false
+spring.cloud.polaris.lossless.port=28080
+
+# 日志级别
logging.level.root=INFO
\ No newline at end of file
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java
index e970716f..1b0745e5 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java
@@ -54,8 +54,6 @@ public static List loadPropertiesSource() {
throw new IllegalStateException("fail to load file " + fileName, e);
}
List propertySources = new ArrayList<>();
- propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));
-
String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
LOGGER.info("load property sources from config path " + configPath);
Properties properties = new Properties();
@@ -71,6 +69,7 @@ public static List loadPropertiesSource() {
throw new IllegalStateException("fail to load config from " + configPath, e);
}
propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties));
+ propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));
return propertySources;
});
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/Utils.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/Utils.java
new file mode 100644
index 00000000..34a2c6f1
--- /dev/null
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/Utils.java
@@ -0,0 +1,60 @@
+/*
+ * Tencent is pleased to support the open source community by making Polaris available.
+ *
+ * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
+ *
+ * Licensed under the BSD 3-Clause License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package cn.polarismesh.agent.plugin.spring.cloud.common;
+
+import org.springframework.core.env.Environment;
+
+public class Utils {
+
+ public static boolean checkKeyExists(Environment environment, String key) {
+ if (null == environment) {
+ return false;
+ }
+ String property = environment.getProperty(key);
+ return null != property && !property.isEmpty();
+ }
+
+ public static boolean checkKeyEnabled(Environment environment, String key) {
+ if (null == environment) {
+ return false;
+ }
+ String property = environment.getProperty(key);
+ return Boolean.parseBoolean(property);
+ }
+
+ /**
+ * check properties has spring.application.name
+ * @param environment spring cloud context environment
+ * @return application name
+ */
+ public static boolean checkSpringApplicationNameExists(Environment environment) {
+ return checkKeyExists(environment, "spring.application.name");
+ }
+
+
+
+ /**
+ * check properties has spring.cloud.polaris.enabled=true
+ * @param environment spring cloud context environment
+ * @return application name
+ */
+ public static boolean checkPolarisEnabled(Environment environment) {
+ return checkKeyEnabled(environment, "spring.cloud.polaris.enabled");
+ }
+
+}