From 14df7d4794372973ea3e0181c4759682519d5ebf Mon Sep 17 00:00:00 2001 From: "lingxiao,wu" <51630311+lingxiao-wu@users.noreply.github.com> Date: Wed, 2 Nov 2022 15:02:37 +0800 Subject: [PATCH] Optimize:optimize spring annotation. (#688) --- CHANGELOG.md | 1 + .../polaris/DiscoveryConfigModifier.java | 9 +- .../DiscoveryPropertiesAutoConfiguration.java | 28 ++++- .../PolarisDiscoveryConfigModifier.java | 59 +++++++++ .../polaris/PolarisDiscoveryProperties.java | 58 +++------ .../discovery/PolarisDiscoveryHandler.java | 24 ++-- .../extend/consul/ConsulConfigModifier.java | 95 +++++++++++++++ .../consul/ConsulContextProperties.java | 114 ++++++------------ .../util/ApplicationContextAwareUtils.java | 2 - .../RpcEnhancementAutoConfiguration.java | 10 +- .../reporter/ExceptionPolarisReporter.java | 9 +- .../reporter/SuccessPolarisReporter.java | 8 +- 12 files changed, 265 insertions(+), 152 deletions(-) create mode 100644 spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryConfigModifier.java create mode 100644 spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulConfigModifier.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 368093730..fcec50bc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ --- - [Optimize:optimize SpringValueProcessor.](https://github.com/Tencent/spring-cloud-tencent/pull/668) +- [Optimize:optimize spring annotation.](https://github.com/Tencent/spring-cloud-tencent/pull/688) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryConfigModifier.java index 0512de81e..cf7a5a28b 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryConfigModifier.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryConfigModifier.java @@ -24,8 +24,6 @@ import com.tencent.polaris.api.config.consumer.ServiceRouterConfig; import com.tencent.polaris.factory.config.ConfigurationImpl; import com.tencent.polaris.plugins.router.healthy.RecoverRouterConfig; -import org.springframework.beans.factory.annotation.Autowired; - /** * Spring Cloud Tencent config Override polaris config. * @@ -33,8 +31,11 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class DiscoveryConfigModifier implements PolarisConfigModifier { - @Autowired - private PolarisDiscoveryProperties polarisDiscoveryProperties; + private final PolarisDiscoveryProperties polarisDiscoveryProperties; + + public DiscoveryConfigModifier(PolarisDiscoveryProperties polarisDiscoveryProperties) { + this.polarisDiscoveryProperties = polarisDiscoveryProperties; + } @Override public void modify(ConfigurationImpl configuration) { diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfiguration.java index 6e9f1b236..c98f64dfb 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfiguration.java @@ -19,8 +19,13 @@ package com.tencent.cloud.polaris; import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; +import com.tencent.cloud.polaris.extend.consul.ConsulConfigModifier; import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties; +import com.tencent.polaris.api.core.ConsumerAPI; +import com.tencent.polaris.api.core.ProviderAPI; +import com.tencent.polaris.client.api.SDKContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -38,12 +43,27 @@ public class DiscoveryPropertiesAutoConfiguration { @Bean @ConditionalOnMissingBean - public PolarisDiscoveryHandler polarisDiscoveryHandler() { - return new PolarisDiscoveryHandler(); + public PolarisDiscoveryHandler polarisDiscoveryHandler(PolarisDiscoveryProperties polarisDiscoveryProperties, + ProviderAPI providerAPI, SDKContext sdkContext, + ConsumerAPI polarisConsumer) { + return new PolarisDiscoveryHandler(polarisDiscoveryProperties, providerAPI, sdkContext, polarisConsumer); } @Bean - public DiscoveryConfigModifier discoveryConfigModifier() { - return new DiscoveryConfigModifier(); + @ConditionalOnMissingBean + public DiscoveryConfigModifier discoveryConfigModifier(PolarisDiscoveryProperties polarisDiscoveryProperties) { + return new DiscoveryConfigModifier(polarisDiscoveryProperties); + } + + @Bean + @ConditionalOnMissingBean + public ConsulConfigModifier consulConfigModifier(@Autowired(required = false) ConsulContextProperties consulContextProperties) { + return new ConsulConfigModifier(consulContextProperties); + } + + @Bean + @ConditionalOnMissingBean + public PolarisDiscoveryConfigModifier polarisDiscoveryConfigModifier(PolarisDiscoveryProperties polarisDiscoveryProperties) { + return new PolarisDiscoveryConfigModifier(polarisDiscoveryProperties); } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryConfigModifier.java new file mode 100644 index 000000000..bbe809d52 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryConfigModifier.java @@ -0,0 +1,59 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris; + +import com.tencent.cloud.common.constant.ContextConstant; +import com.tencent.cloud.polaris.context.PolarisConfigModifier; +import com.tencent.polaris.factory.config.ConfigurationImpl; +import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl; +import com.tencent.polaris.factory.config.provider.RegisterConfigImpl; + +/** + * @author lingxiao.wlx + */ +public class PolarisDiscoveryConfigModifier implements PolarisConfigModifier { + + private static final String ID = "polaris"; + + private final PolarisDiscoveryProperties polarisDiscoveryProperties; + + public PolarisDiscoveryConfigModifier(PolarisDiscoveryProperties polarisDiscoveryProperties) { + this.polarisDiscoveryProperties = polarisDiscoveryProperties; + } + + @Override + public void modify(ConfigurationImpl configuration) { + if (polarisDiscoveryProperties != null) { + DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl(); + discoveryConfig.setServerConnectorId(ID); + discoveryConfig.setEnable(polarisDiscoveryProperties.isEnabled()); + configuration.getConsumer().getDiscoveries().add(discoveryConfig); + + RegisterConfigImpl registerConfig = new RegisterConfigImpl(); + registerConfig.setServerConnectorId(ID); + registerConfig.setEnable(polarisDiscoveryProperties.isRegisterEnabled()); + configuration.getProvider().getRegisters().add(registerConfig); + } + } + + @Override + public int getOrder() { + return ContextConstant.ModifierOrder.LAST; + } +} diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java index 05b9cacc8..731676858 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java @@ -19,16 +19,9 @@ package com.tencent.cloud.polaris; import com.tencent.cloud.common.constant.ContextConstant; -import com.tencent.cloud.polaris.context.PolarisConfigModifier; -import com.tencent.polaris.factory.config.ConfigurationImpl; -import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl; -import com.tencent.polaris.factory.config.provider.RegisterConfigImpl; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; import static com.tencent.cloud.common.constant.ContextConstant.DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL; @@ -115,6 +108,7 @@ public class PolarisDiscoveryProperties { */ private Long serviceListRefreshInterval = 60000L; + public boolean isHeartbeatEnabled() { return heartbeatEnabled; } @@ -222,6 +216,22 @@ public class PolarisDiscoveryProperties { this.heartbeatInterval = heartbeatInterval; } + public Boolean getEnabled() { + return enabled; + } + + public Boolean getRegisterEnabled() { + return registerEnabled; + } + + public void setRegisterEnabled(Boolean registerEnabled) { + this.registerEnabled = registerEnabled; + } + + public Boolean getHeartbeatEnabled() { + return heartbeatEnabled; + } + @Override public String toString() { return "PolarisDiscoveryProperties{" + @@ -240,38 +250,4 @@ public class PolarisDiscoveryProperties { ", serviceListRefreshInterval=" + serviceListRefreshInterval + '}'; } - - @Bean - @ConditionalOnMissingBean - public PolarisDiscoveryConfigModifier polarisDiscoveryConfigModifier() { - return new PolarisDiscoveryConfigModifier(); - } - - private static class PolarisDiscoveryConfigModifier implements PolarisConfigModifier { - - private static final String ID = "polaris"; - - @Autowired(required = false) - private PolarisDiscoveryProperties polarisDiscoveryProperties; - - @Override - public void modify(ConfigurationImpl configuration) { - if (polarisDiscoveryProperties != null) { - DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl(); - discoveryConfig.setServerConnectorId(ID); - discoveryConfig.setEnable(polarisDiscoveryProperties.enabled); - configuration.getConsumer().getDiscoveries().add(discoveryConfig); - - RegisterConfigImpl registerConfig = new RegisterConfigImpl(); - registerConfig.setServerConnectorId(ID); - registerConfig.setEnable(polarisDiscoveryProperties.registerEnabled); - configuration.getProvider().getRegisters().add(registerConfig); - } - } - - @Override - public int getOrder() { - return ContextConstant.ModifierOrder.LAST; - } - } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java index 2388c1381..51e16e34d 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java @@ -28,28 +28,28 @@ import com.tencent.polaris.api.rpc.InstancesResponse; import com.tencent.polaris.api.rpc.ServicesResponse; import com.tencent.polaris.client.api.SDKContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - /** * Discovery Handler for Polaris. * * @author Haotian Zhang, Andrew Shan, Jie Cheng */ -@Component public class PolarisDiscoveryHandler { - @Autowired - private PolarisDiscoveryProperties polarisDiscoveryProperties; + private final PolarisDiscoveryProperties polarisDiscoveryProperties; + + private final ProviderAPI providerAPI; - @Autowired - private ProviderAPI providerAPI; + private final SDKContext sdkContext; - @Autowired - private SDKContext sdkContext; + private final ConsumerAPI polarisConsumer; - @Autowired - private ConsumerAPI polarisConsumer; + public PolarisDiscoveryHandler(PolarisDiscoveryProperties polarisDiscoveryProperties, + ProviderAPI providerAPI, SDKContext sdkContext, ConsumerAPI polarisConsumer) { + this.polarisDiscoveryProperties = polarisDiscoveryProperties; + this.providerAPI = providerAPI; + this.sdkContext = sdkContext; + this.polarisConsumer = polarisConsumer; + } /** * Get a list of healthy instances. diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulConfigModifier.java new file mode 100644 index 000000000..70a4f703f --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulConfigModifier.java @@ -0,0 +1,95 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.extend.consul; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; + +import com.tencent.cloud.common.constant.ContextConstant; +import com.tencent.cloud.polaris.context.PolarisConfigModifier; +import com.tencent.polaris.api.config.plugin.DefaultPlugins; +import com.tencent.polaris.factory.config.ConfigurationImpl; +import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl; +import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl; +import com.tencent.polaris.factory.config.provider.RegisterConfigImpl; +import com.tencent.polaris.plugins.connector.common.constant.ConsulConstant; +import org.apache.commons.lang.StringUtils; + +import org.springframework.util.CollectionUtils; + +/** + * @author lingxiao.wlx + */ +public class ConsulConfigModifier implements PolarisConfigModifier { + private static final String ID = "consul"; + + private final ConsulContextProperties consulContextProperties; + + public ConsulConfigModifier(ConsulContextProperties consulContextProperties) { + this.consulContextProperties = consulContextProperties; + } + + @Override + public void modify(ConfigurationImpl configuration) { + if (consulContextProperties != null && consulContextProperties.isEnabled()) { + if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())) { + configuration.getGlobal().setServerConnectors(new ArrayList<>()); + } + if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors()) + && null != configuration.getGlobal().getServerConnector()) { + configuration.getGlobal().getServerConnectors().add(configuration.getGlobal().getServerConnector()); + } + ServerConnectorConfigImpl serverConnectorConfig = new ServerConnectorConfigImpl(); + serverConnectorConfig.setId(ID); + serverConnectorConfig.setAddresses( + Collections.singletonList(consulContextProperties.getHost() + ":" + consulContextProperties.getPort())); + serverConnectorConfig.setProtocol(DefaultPlugins.SERVER_CONNECTOR_CONSUL); + Map metadata = serverConnectorConfig.getMetadata(); + if (StringUtils.isNotBlank(consulContextProperties.getServiceName())) { + metadata.put(ConsulConstant.MetadataMapKey.SERVICE_NAME_KEY, consulContextProperties.getServiceName()); + } + if (StringUtils.isNotBlank(consulContextProperties.getInstanceId())) { + metadata.put(ConsulConstant.MetadataMapKey.INSTANCE_ID_KEY, consulContextProperties.getInstanceId()); + } + if (consulContextProperties.isPreferIpAddress() + && StringUtils.isNotBlank(consulContextProperties.getIpAddress())) { + metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY, + String.valueOf(consulContextProperties.isPreferIpAddress())); + metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, consulContextProperties.getIpAddress()); + } + configuration.getGlobal().getServerConnectors().add(serverConnectorConfig); + + DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl(); + discoveryConfig.setServerConnectorId(ID); + discoveryConfig.setEnable(consulContextProperties.isDiscoveryEnabled()); + configuration.getConsumer().getDiscoveries().add(discoveryConfig); + + RegisterConfigImpl registerConfig = new RegisterConfigImpl(); + registerConfig.setServerConnectorId(ID); + registerConfig.setEnable(consulContextProperties.isRegister()); + configuration.getProvider().getRegisters().add(registerConfig); + } + } + + @Override + public int getOrder() { + return ContextConstant.ModifierOrder.LAST; + } +} diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulContextProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulContextProperties.java index 7c2e4ec1a..ad98e009b 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulContextProperties.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulContextProperties.java @@ -17,26 +17,8 @@ package com.tencent.cloud.polaris.extend.consul; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Map; - -import com.tencent.cloud.common.constant.ContextConstant.ModifierOrder; -import com.tencent.cloud.polaris.context.PolarisConfigModifier; -import com.tencent.polaris.api.config.plugin.DefaultPlugins; -import com.tencent.polaris.factory.config.ConfigurationImpl; -import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl; -import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl; -import com.tencent.polaris.factory.config.provider.RegisterConfigImpl; -import com.tencent.polaris.plugins.connector.common.constant.ConsulConstant.MetadataMapKey; -import org.apache.commons.lang.StringUtils; - -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.util.CollectionUtils; /** * Discovery configuration of Consul. @@ -105,65 +87,43 @@ public class ConsulContextProperties { return discoveryEnabled; } - @Bean - @ConditionalOnMissingBean - public ConsulConfigModifier consulConfigModifier() { - return new ConsulConfigModifier(); - } - - private static class ConsulConfigModifier implements PolarisConfigModifier { - - private static final String ID = "consul"; - - @Autowired(required = false) - private ConsulContextProperties consulContextProperties; - - @Override - public void modify(ConfigurationImpl configuration) { - if (consulContextProperties != null && consulContextProperties.enabled) { - if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())) { - configuration.getGlobal().setServerConnectors(new ArrayList<>()); - } - if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors()) - && null != configuration.getGlobal().getServerConnector()) { - configuration.getGlobal().getServerConnectors().add(configuration.getGlobal().getServerConnector()); - } - ServerConnectorConfigImpl serverConnectorConfig = new ServerConnectorConfigImpl(); - serverConnectorConfig.setId(ID); - serverConnectorConfig.setAddresses( - Collections.singletonList(consulContextProperties.host + ":" + consulContextProperties.port)); - serverConnectorConfig.setProtocol(DefaultPlugins.SERVER_CONNECTOR_CONSUL); - Map metadata = serverConnectorConfig.getMetadata(); - if (StringUtils.isNotBlank(consulContextProperties.serviceName)) { - metadata.put(MetadataMapKey.SERVICE_NAME_KEY, consulContextProperties.serviceName); - } - if (StringUtils.isNotBlank(consulContextProperties.instanceId)) { - metadata.put(MetadataMapKey.INSTANCE_ID_KEY, consulContextProperties.instanceId); - } - if (consulContextProperties.preferIpAddress - && StringUtils.isNotBlank(consulContextProperties.ipAddress)) { - metadata.put(MetadataMapKey.PREFER_IP_ADDRESS_KEY, - String.valueOf(consulContextProperties.preferIpAddress)); - metadata.put(MetadataMapKey.IP_ADDRESS_KEY, consulContextProperties.ipAddress); - } - configuration.getGlobal().getServerConnectors().add(serverConnectorConfig); - - DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl(); - discoveryConfig.setServerConnectorId(ID); - discoveryConfig.setEnable(consulContextProperties.discoveryEnabled); - configuration.getConsumer().getDiscoveries().add(discoveryConfig); - - RegisterConfigImpl registerConfig = new RegisterConfigImpl(); - registerConfig.setServerConnectorId(ID); - registerConfig.setEnable(consulContextProperties.register); - configuration.getProvider().getRegisters().add(registerConfig); - } - } - - @Override - public int getOrder() { - return ModifierOrder.LAST; - } + public void setRegister(boolean register) { + this.register = register; + } + + public void setDiscoveryEnabled(boolean discoveryEnabled) { + this.discoveryEnabled = discoveryEnabled; + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + public boolean isPreferIpAddress() { + return preferIpAddress; + } + public void setPreferIpAddress(boolean preferIpAddress) { + this.preferIpAddress = preferIpAddress; } } diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java index b611cc04f..98a6a4341 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java @@ -21,14 +21,12 @@ import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.lang.NonNull; -import org.springframework.stereotype.Component; /** * Spring Context Util. * * @author Hongwei Zhu */ -@Component public class ApplicationContextAwareUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java index 46d24fa9d..53bd5f414 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java @@ -88,13 +88,15 @@ public class RpcEnhancementAutoConfiguration { static class PolarisReporterConfig { @Bean - public SuccessPolarisReporter successPolarisReporter(RpcEnhancementReporterProperties properties) { - return new SuccessPolarisReporter(properties); + public SuccessPolarisReporter successPolarisReporter(RpcEnhancementReporterProperties properties, + @Autowired(required = false) ConsumerAPI consumerAPI) { + return new SuccessPolarisReporter(properties, consumerAPI); } @Bean - public ExceptionPolarisReporter exceptionPolarisReporter(RpcEnhancementReporterProperties properties) { - return new ExceptionPolarisReporter(properties); + public ExceptionPolarisReporter exceptionPolarisReporter(RpcEnhancementReporterProperties properties, + @Autowired(required = false) ConsumerAPI consumerAPI) { + return new ExceptionPolarisReporter(properties, consumerAPI); } } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java index 1f1c4366b..0e1b2c87a 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java @@ -31,7 +31,6 @@ import feign.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; /** @@ -43,11 +42,13 @@ public class ExceptionPolarisReporter implements EnhancedFeignPlugin { private static final Logger LOG = LoggerFactory.getLogger(ExceptionPolarisReporter.class); private final RpcEnhancementReporterProperties reporterProperties; - @Autowired(required = false) - private ConsumerAPI consumerAPI; - public ExceptionPolarisReporter(RpcEnhancementReporterProperties reporterProperties) { + private final ConsumerAPI consumerAPI; + + public ExceptionPolarisReporter(RpcEnhancementReporterProperties reporterProperties, + ConsumerAPI consumerAPI) { this.reporterProperties = reporterProperties; + this.consumerAPI = consumerAPI; } @Override diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java index f7d59b512..2fefd6dcf 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java @@ -30,7 +30,6 @@ import feign.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; import org.springframework.http.HttpStatus; @@ -42,11 +41,12 @@ import org.springframework.http.HttpStatus; public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter implements EnhancedFeignPlugin { private static final Logger LOG = LoggerFactory.getLogger(SuccessPolarisReporter.class); - @Autowired(required = false) - private ConsumerAPI consumerAPI; - public SuccessPolarisReporter(RpcEnhancementReporterProperties properties) { + private final ConsumerAPI consumerAPI; + + public SuccessPolarisReporter(RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI) { super(properties); + this.consumerAPI = consumerAPI; } @Override