From 9a0a8eb207298ba84de471f5a19c45c86e8e457b Mon Sep 17 00:00:00 2001 From: fredrikliu Date: Thu, 20 Jun 2024 21:39:12 +0800 Subject: [PATCH] change application.propertirtes --- .../src/main/resources/bootstrap.properties | 8 +++-- .../src/main/resources/bootstrap.properties | 2 ++ .../src/main/resources/bootstrap.properties | 8 ++--- .../src/main/resources/application.properties | 2 +- .../src/main/resources/bootstrap.properties | 36 +++++++++---------- .../src/main/resources/application.properties | 4 ++- .../src/main/resources/application.properties | 2 ++ .../cloud/inject/CommonBeanInjector.java | 12 +------ .../cloud/inject/RouterBeanInjector.java | 27 +++++++++----- .../ConfigurationParserInterceptor.java | 4 +-- .../spring-cloud/application.properties | 6 +++- .../cloud/common/PropertiesProvider.java | 2 ++ 12 files changed, 64 insertions(+), 49 deletions(-) diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties index 664d5d3c..44dcc14f 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties @@ -2,10 +2,12 @@ server.port=65002 spring.application.name=service-consumer-2022 management.endpoints.web.exposure.include=* spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -spring.cloud.nacos.discovery.fail-fast=true - +spring.cloud.nacos.config.server-addr=127.0.0.1:8848 +spring.cloud.nacos.discovery.enabled=true +spring.cloud.nacos.config.enabled=true spring.cloud.nacos.username=nacos -spring.cloud.nacos.password=nacos +spring.cloud.nacos.password=uu3T2L9q +spring.cloud.nacos.discovery.fail-fast=true feign.sentinel.enabled=true diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties index 672e7e8e..31e75db7 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties @@ -1,6 +1,8 @@ server.port=65001 spring.application.name=service-provider-2022 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 +spring.cloud.nacos.config.server-addr=111.230.121.115:8848 +spring.cloud.nacos.config.enabled=true spring.cloud.nacos.discovery.enabled=true #spring.cloud.nacos.discovery.instance-enabled=true #only register IPv4 instance diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties index e59c130d..98e9f0c1 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties @@ -1,13 +1,13 @@ server.port=65002 -spring.application.name=service-consumer-2022 +spring.application.name=service-consumer-2023 management.endpoints.web.exposure.include=* -spring.cloud.nacos.discovery.server-addr=111.230.121.115:8848 -spring.cloud.nacos.config.server-addr=111.230.121.115:8848 +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.discovery.fail-fast=true spring.cloud.nacos.discovery.enabled=true spring.cloud.nacos.config.enabled=true spring.cloud.nacos.username=nacos -spring.cloud.nacos.password=uu3T2L9q +spring.cloud.nacos.password=nacos feign.sentinel.enabled=true diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.properties index 31e75db7..29dbdc7b 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port=65001 spring.application.name=service-provider-2022 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -spring.cloud.nacos.config.server-addr=111.230.121.115:8848 +spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.enabled=true spring.cloud.nacos.discovery.enabled=true #spring.cloud.nacos.discovery.instance-enabled=true 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 31e75db7..b45f00e2 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,18 +1,18 @@ -server.port=65001 -spring.application.name=service-provider-2022 -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -spring.cloud.nacos.config.server-addr=111.230.121.115:8848 -spring.cloud.nacos.config.enabled=true -spring.cloud.nacos.discovery.enabled=true -#spring.cloud.nacos.discovery.instance-enabled=true -#only register IPv4 instance -#spring.cloud.nacos.discovery.ip-type=IPv4 -#only register IPv6 instance -#spring.cloud.nacos.discovery.ip-type=IPv6 - -spring.cloud.nacos.username=nacos -spring.cloud.nacos.password=nacos - -management.endpoints.web.exposure.include=* -management.endpoint.health.show-details=always -spring.main.allow-circular-references=true \ No newline at end of file +#server.port=65001 +#spring.application.name=service-provider-2022 +#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 +#spring.cloud.nacos.discovery.enabled=true +##spring.cloud.nacos.discovery.instance-enabled=true +##only register IPv4 instance +##spring.cloud.nacos.discovery.ip-type=IPv4 +##only register IPv6 instance +##spring.cloud.nacos.discovery.ip-type=IPv6 +# +#spring.cloud.nacos.username=nacos +#spring.cloud.nacos.password=nacos +# +#management.endpoints.web.exposure.include=* +#management.endpoint.health.show-details=always +#spring.main.allow-circular-references=true \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties index a0dd8275..ad3cf2cd 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties @@ -2,8 +2,10 @@ spring.application.name=service-consumer-hoxton server.port=18083 management.endpoints.web.exposure.include=* 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.discovery.fail-fast=true - +spring.cloud.nacos.config.enabled=true +spring.cloud.nacos.discovery.enabled=true spring.cloud.nacos.username=nacos spring.cloud.nacos.password=nacos diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties index 3cfbe8b5..5cf6fe94 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties @@ -1,6 +1,8 @@ server.port=0 spring.application.name=service-provider-hoxton 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 spring.cloud.nacos.discovery.enabled=true #spring.cloud.nacos.discovery.instance-enabled=true #only register IPv4 instance diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java index 4fb14366..7c990b41 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java @@ -65,17 +65,7 @@ public void onApplicationStartup(Object configurationParser, Constructor conf ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, applicationContextAwareUtils, Constant.DEFAULT_EXCLUSION_FILTER); registry.registerBeanDefinition("applicationContextAwareUtils", BeanDefinitionBuilder.genericBeanDefinition( ApplicationContextAwareUtils.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 routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration"); - ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); - registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( - RouterAutoConfiguration.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/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 758cebce..e8d0c87b 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 @@ -58,6 +58,25 @@ public String getModule() { @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 + @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( @@ -78,13 +97,5 @@ public void onBootstrapStartup(Object configurationParser, Constructor config ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition()); - LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); - } - - - @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()); } } diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java index 5213a6ed..2c56dbb3 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java @@ -117,7 +117,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry"); Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment"); for (BeanInjector beanInjector : beanInjectors) { - if (!(beanInjector instanceof CommonBeanInjector)) { + if (!(beanInjector instanceof RouterBeanInjector)) { LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule()); beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment); } @@ -140,7 +140,7 @@ public void before(Object target, Object[] args) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry"); Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment"); for (BeanInjector beanInjector : beanInjectors) { - if (beanInjector instanceof CommonBeanInjector) { + if (beanInjector instanceof RouterBeanInjector) { LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule()); beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment); } diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties index d171d2dc..44adfa4f 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties @@ -45,4 +45,8 @@ logging.level.root=INFO # switch for nacos discovery enable spring.cloud.nacos.discovery.enabled=false # switch for nacos config enable -spring.cloud.nacos.config.enabled=false \ No newline at end of file +spring.cloud.nacos.config.enabled=false +# switch for lossless enable +spring.cloud.polaris.lossless.enabled=true +spring.cloud.polaris.lossless.port=28080 +spring.cloud.polaris.lossless.delayRegisterInterval=30000 \ 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 015fed4b..f4aa3d60 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 @@ -67,6 +67,8 @@ public static List loadPropertiesSource() { } catch (IOException e) { throw new IllegalStateException("fail to load config from " + configPath, e); } + properties.setProperty("spring.cloud.nacos.config.enabled", "false"); + properties.setProperty("spring.cloud.nacos.discovery.enabled", "false"); propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties)); propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties)); return propertySources;