diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java index 13244af84..5f5f78092 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java @@ -66,7 +66,7 @@ public class PolarisConfigAutoConfiguration { public SpringValueProcessor springValueProcessor() { return new SpringValueProcessor(); } - + @Bean public SpringValueDefinitionProcessor springValueDefinitionProcessor() { return new SpringValueDefinitionProcessor(); diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisPropertySourceAutoRefresher.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisPropertySourceAutoRefresher.java index 415529385..e099c55f7 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisPropertySourceAutoRefresher.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisPropertySourceAutoRefresher.java @@ -89,7 +89,6 @@ public class PolarisPropertySourceAutoRefresher this.placeholderHelper = SpringInjector.getInstance(PlaceholderHelper.class); this.typeConverterHasConvertIfNecessaryWithFieldParameter = testTypeConverterHasConvertIfNecessaryWithFieldParameter(); - } @Override @@ -136,7 +135,7 @@ public class PolarisPropertySourceAutoRefresher Map source = polarisPropertySource .getSource(); - + for (String changedKey : configKVFileChangeEvent.changedKeys()) { // 1. check whether the changed key is relevant @@ -164,14 +163,15 @@ public class PolarisPropertySourceAutoRefresher LOGGER.info("Auto update polaris changed value successfully, new value: {}, {}", value, springValue); - } catch (Throwable ex) { + } + catch (Throwable ex) { LOGGER.error("Auto update polaris changed value failed, {}", springValue.toString(), ex); } } /** - * Logic transplanted from DefaultListableBeanFactory + * Logic transplanted from DefaultListableBeanFactory. * * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, * java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) @@ -183,16 +183,19 @@ public class PolarisPropertySourceAutoRefresher if (springValue.isJson()) { value = parseJsonValue((String) value, springValue.getTargetType()); - } else { + } + else { if (springValue.isField()) { // org.springframework.beans.TypeConverter#convertIfNecessary(java.lang.Object, java.lang.Class, java.lang.reflect.Field) is available from Spring 3.2.0+ if (typeConverterHasConvertIfNecessaryWithFieldParameter) { value = this.typeConverter .convertIfNecessary(value, springValue.getTargetType(), springValue.getField()); - } else { + } + else { value = this.typeConverter.convertIfNecessary(value, springValue.getTargetType()); } - } else { + } + else { value = this.typeConverter.convertIfNecessary(value, springValue.getTargetType(), springValue.getMethodParameter()); } @@ -204,7 +207,8 @@ public class PolarisPropertySourceAutoRefresher private Object parseJsonValue(String json, Class targetType) { try { return JacksonUtils.json2JavaBean(json, targetType); - } catch (Throwable ex) { + } + catch (Throwable ex) { LOGGER.error("Parsing json '{}' to type {} failed!", json, targetType, ex); throw ex; } @@ -213,7 +217,8 @@ public class PolarisPropertySourceAutoRefresher private boolean testTypeConverterHasConvertIfNecessaryWithFieldParameter() { try { TypeConverter.class.getMethod("convertIfNecessary", Object.class, Class.class, Field.class); - } catch (Throwable ex) { + } + catch (Throwable ex) { return false; } return true; diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/AbstractPolarisProcessor.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/AbstractPolarisProcessor.java index da3429b7c..ac81f6b96 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/AbstractPolarisProcessor.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/AbstractPolarisProcessor.java @@ -54,13 +54,20 @@ public abstract class AbstractPolarisProcessor implements BeanPostProcessor, Pri return bean; } + /** - * subclass should implement this method to process field + * subclass should implement this method to process field. + * @param bean bean + * @param beanName beanName + * @param field field */ protected abstract void processField(Object bean, String beanName, Field field); /** - * subclass should implement this method to process method + * subclass should implement this method to process method. + * @param bean bean + * @param beanName beanName + * @param method method */ protected abstract void processMethod(Object bean, String beanName, Method method); diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java index 1428280a9..92f0bf0e2 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java @@ -36,7 +36,7 @@ import org.springframework.context.annotation.Bean; public class SpringValueProcessor extends AbstractPolarisProcessor implements BeanFactoryPostProcessor, BeanFactoryAware { private static final Logger logger = LoggerFactory.getLogger(SpringValueProcessor.class); - + private final PlaceholderHelper placeholderHelper; private final SpringValueRegistry springValueRegistry; @@ -111,10 +111,12 @@ public class SpringValueProcessor extends AbstractPolarisProcessor implements Be if (member instanceof Field) { Field field = (Field) member; springValue = new SpringValue(key, value.value(), bean, beanName, field, false); - } else if (member instanceof Method) { + } + else if (member instanceof Method) { Method method = (Method) member; springValue = new SpringValue(key, value.value(), bean, beanName, method, false); - } else { + } + else { logger.error("polaris @Value annotation currently only support to be used on methods and fields, " + "but is used on {}", member.getClass()); return; @@ -143,7 +145,8 @@ public class SpringValueProcessor extends AbstractPolarisProcessor implements Be bean, beanName, method, false); springValueRegistry.register(beanFactory, definition.getKey(), springValue); logger.debug("Monitoring {}", springValue); - } catch (Throwable ex) { + } + catch (Throwable ex) { logger.error("Failed to enable auto update feature for {}.{}", bean.getClass(), definition.getPropertyName()); } diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/PlaceholderHelper.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/PlaceholderHelper.java index 3d1eb37dc..a272d2bfe 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/PlaceholderHelper.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/PlaceholderHelper.java @@ -44,11 +44,13 @@ public class PlaceholderHelper { private static final String EXPRESSION_PREFIX = "#{"; private static final String EXPRESSION_SUFFIX = "}"; + /** * Resolve placeholder property values, e.g. - *
- *
- * "${somePropertyValue}" -> "the actual property value" + * @param beanFactory beanFactory + * @param beanName beanName + * @param placeholder placeholder + * @return "${somePropertyValue}" -> "the actual property value" */ public Object resolvePropertyValue(ConfigurableBeanFactory beanFactory, String beanName, String placeholder) { // resolve string value @@ -74,6 +76,8 @@ public class PlaceholderHelper { /** * Extract keys from placeholder, e.g. + * @param propertyString propertyString + * @return *