diff --git a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebIpAndPortHolder.java b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebIpAndPortHolder.java index aad45db9..04de2355 100644 --- a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebIpAndPortHolder.java +++ b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebIpAndPortHolder.java @@ -22,6 +22,7 @@ import cn.hippo4j.common.model.WebIpAndPortInfo; import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.core.toolkit.inet.InetUtils; +import lombok.NoArgsConstructor; import org.springframework.boot.web.server.WebServer; import java.util.Arrays; @@ -29,37 +30,35 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; /** - * Ip and port Holder + * Ip and port holder. */ +@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) public class WebIpAndPortHolder { - private static boolean support = false; + private static boolean SUPPORT_VERSION = false; + static { try { Class.forName("org.springframework.boot.web.server.WebServer"); - support = true; - } catch (Exception e) { - + SUPPORT_VERSION = true; + } catch (Exception ignored) { } } + /** * Application ip and application post */ - protected static AtomicReference webIpAndPort = new AtomicReference<>(); + protected static AtomicReference WEB_IP_AND_PORT = new AtomicReference<>(); public static final String ALL = "*"; protected static final String SEPARATOR = ","; - private WebIpAndPortHolder() { - - } - protected static void initIpAndPort() { - if (!support) { + if (!SUPPORT_VERSION) { return; } - webIpAndPort.compareAndSet(null, getWebIpAndPortInfo()); + WEB_IP_AND_PORT.compareAndSet(null, getWebIpAndPortInfo()); } private static WebIpAndPortInfo getWebIpAndPortInfo() { @@ -76,19 +75,19 @@ public class WebIpAndPortHolder { } /** - * get WebIpAndPortInfo, If it is null, initialize it + * get WebIpAndPortInfo, If it is null, initialize it. * - * @return WebIpAndPortInfo + * @return Web ip and port info */ public static WebIpAndPortInfo getWebIpAndPort() { - if (webIpAndPort.get() == null) { + if (WEB_IP_AND_PORT.get() == null) { initIpAndPort(); } - return WebIpAndPortHolder.webIpAndPort.get(); + return WebIpAndPortHolder.WEB_IP_AND_PORT.get(); } /** - * Check the new properties and instance IP and port + * Check the new properties and instance IP and port. * * @param nodes nodes in properties * @return Whether it meets the conditions @@ -105,5 +104,4 @@ public class WebIpAndPortHolder { .filter(Objects::nonNull) .anyMatch(each -> each.check(webIpAndPort.getIpSegment(), webIpAndPort.getPort())); } - } \ No newline at end of file diff --git a/hippo4j-common/pom.xml b/hippo4j-common/pom.xml index deaebf44..b127ba64 100644 --- a/hippo4j-common/pom.xml +++ b/hippo4j-common/pom.xml @@ -49,7 +49,6 @@ org.projectlombok lombok - org.springframework.boot spring-boot-starter-test diff --git a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/pom.xml b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/pom.xml similarity index 87% rename from hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/pom.xml rename to hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/pom.xml index 0fe053a1..b2afd209 100644 --- a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/pom.xml +++ b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/pom.xml @@ -7,7 +7,7 @@ hippo4j-example ${revision} - hippo4j-config-apollo-spring-boot-1.5-starter-example + hippo4j-config-apollo-spring-boot-1x-starter-example true @@ -37,15 +37,9 @@ ${revision} - cn.hippo4j - hippo4j-config-spring-boot-1.5-starter + hippo4j-config-spring-boot-1x-starter ${revision} diff --git a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot15ExampleApplication.java b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot1xExampleApplication.java similarity index 90% rename from hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot15ExampleApplication.java rename to hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot1xExampleApplication.java index 801bb840..8771b389 100644 --- a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot15ExampleApplication.java +++ b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/java/cn/hippo4j/example/config/apollo/ConfigApolloSpringBoot1xExampleApplication.java @@ -23,9 +23,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableDynamicThreadPool @SpringBootApplication(scanBasePackages = "cn.hippo4j.example.core") -public class ConfigApolloSpringBoot15ExampleApplication { +public class ConfigApolloSpringBoot1xExampleApplication { public static void main(String[] args) { - SpringApplication.run(ConfigApolloSpringBoot15ExampleApplication.class, args); + SpringApplication.run(ConfigApolloSpringBoot1xExampleApplication.class, args); } } diff --git a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/resources/bootstrap.properties b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/resources/bootstrap.properties similarity index 86% rename from hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/resources/bootstrap.properties rename to hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/resources/bootstrap.properties index cb44a4f1..610f14c7 100644 --- a/hippo4j-example/hippo4j-config-apollo-spring-boot-1.5-starter-example/src/main/resources/bootstrap.properties +++ b/hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example/src/main/resources/bootstrap.properties @@ -21,16 +21,11 @@ spring.dynamic.thread-pool.banner=true spring.dynamic.thread-pool.check-state-interval=3 spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT -spring.dynamic.thread-pool.notify-platforms[0].secret-key=ac0426a5-c712-474c-9bff-72b8b8f5caff -spring.dynamic.thread-pool.notify-platforms[1].platform=DING -spring.dynamic.thread-pool.notify-platforms[1].secret-key=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55 -spring.dynamic.thread-pool.notify-platforms[2].platform=LARK -spring.dynamic.thread-pool.notify-platforms[2].secret-key=2cbf2808-3839-4c26-a04d-fd201dd51f9e +spring.dynamic.thread-pool.notify-platforms[0].token=ac0426a5-c712-474c-9bff-72b8b8f5caff spring.dynamic.thread-pool.apollo.namespace=application spring.dynamic.thread-pool.config-file-type=properties - spring.dynamic.thread-pool.executors[0].active-alarm = 80 spring.dynamic.thread-pool.executors[0].alarm = true spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true diff --git a/hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/pom.xml b/hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/pom.xml similarity index 93% rename from hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/pom.xml rename to hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/pom.xml index b9a5e9b2..9aa0940b 100644 --- a/hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/pom.xml +++ b/hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/pom.xml @@ -7,7 +7,7 @@ hippo4j-example ${revision} - hippo4j-config-nacos-spring-boot-1.5-starter-example + hippo4j-config-nacos-spring-boot-1x-starter-example true @@ -16,7 +16,6 @@ - com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config @@ -47,7 +46,7 @@ cn.hippo4j - hippo4j-config-spring-boot-1.5-starter + hippo4j-config-spring-boot-1x-starter ${revision} @@ -67,5 +66,4 @@ spring-boot-starter-actuator - diff --git a/hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/src/main/java/cn/hippo4j/example/config/nacos/ConfigNacosSpringBoot15ExampleApplication.java b/hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/src/main/java/cn/hippo4j/example/config/nacos/ConfigNacosSpringBoot15ExampleApplication.java similarity index 100% rename from hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/src/main/java/cn/hippo4j/example/config/nacos/ConfigNacosSpringBoot15ExampleApplication.java rename to hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/src/main/java/cn/hippo4j/example/config/nacos/ConfigNacosSpringBoot15ExampleApplication.java diff --git a/hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/src/main/resources/bootstrap.properties b/hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/src/main/resources/bootstrap.properties similarity index 100% rename from hippo4j-example/hippo4j-config-nacos-spring-boot-1.5-starter-example/src/main/resources/bootstrap.properties rename to hippo4j-example/hippo4j-config-nacos-spring-boot-1x-starter-example/src/main/resources/bootstrap.properties diff --git a/hippo4j-example/pom.xml b/hippo4j-example/pom.xml index 82389b21..8672119d 100644 --- a/hippo4j-example/pom.xml +++ b/hippo4j-example/pom.xml @@ -10,6 +10,10 @@ hippo4j-example pom + + true + + hippo4j-example-core hippo4j-spring-boot-starter-example @@ -23,11 +27,7 @@ hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq-example hippo4j-spring-boot-starter-adapter-rocketmq-example hippo4j-config-etcd-spring-boot-starter-example - hippo4j-config-nacos-spring-boot-1.5-starter-example - hippo4j-config-apollo-spring-boot-1.5-starter-example + hippo4j-config-nacos-spring-boot-1x-starter-example + hippo4j-config-apollo-spring-boot-1x-starter-example - - - true - diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/resources/META-INF/spring.factories b/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 20dfeef4..00000000 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot15x.starter.config.ConfigHandlerConfiguration \ No newline at end of file diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/pom.xml b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/pom.xml similarity index 91% rename from hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/pom.xml rename to hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/pom.xml index f5c1fa1c..5a95141a 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/pom.xml +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/pom.xml @@ -2,15 +2,13 @@ + 4.0.0 cn.hippo4j hippo4j-spring-boot ${revision} - - 4.0.0 - - hippo4j-config-spring-boot-1.5-starter + hippo4j-config-spring-boot-1x-starter 8 diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/config/ConfigHandlerConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/config/ConfigHandlerAutoConfiguration.java similarity index 78% rename from hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/config/ConfigHandlerConfiguration.java rename to hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/config/ConfigHandlerAutoConfiguration.java index d8164f0f..4a5b147a 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/config/ConfigHandlerConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/config/ConfigHandlerAutoConfiguration.java @@ -15,22 +15,22 @@ * limitations under the License. */ -package cn.hippo4j.config.springboot15x.starter.config; +package cn.hippo4j.config.springboot1x.starter.config; import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt; -import cn.hippo4j.config.springboot15x.starter.refresher.SpringBoot15BootstrapConfigPropertiesBinderAdapt; +import cn.hippo4j.config.springboot1x.starter.refresher.SpringBoot1xBootstrapConfigPropertiesBinderAdapt; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -@Configuration -public class ConfigHandlerConfiguration { +/** + * Config handler auto configuration. + */ +public class ConfigHandlerAutoConfiguration { @Bean @ConditionalOnClass(RelaxedDataBinder.class) public BootstrapConfigPropertiesBinderAdapt bootstrapConfigPropertiesBinderAdapt() { - return new SpringBoot15BootstrapConfigPropertiesBinderAdapt(); + return new SpringBoot1xBootstrapConfigPropertiesBinderAdapt(); } - } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/refresher/SpringBoot15BootstrapConfigPropertiesBinderAdapt.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/refresher/SpringBoot1xBootstrapConfigPropertiesBinderAdapt.java similarity index 95% rename from hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/refresher/SpringBoot15BootstrapConfigPropertiesBinderAdapt.java rename to hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/refresher/SpringBoot1xBootstrapConfigPropertiesBinderAdapt.java index 41e771c7..26a35088 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/cn/hippo4j/config/springboot15x/starter/refresher/SpringBoot15BootstrapConfigPropertiesBinderAdapt.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/cn/hippo4j/config/springboot1x/starter/refresher/SpringBoot1xBootstrapConfigPropertiesBinderAdapt.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.config.springboot15x.starter.refresher; +package cn.hippo4j.config.springboot1x.starter.refresher; import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt; @@ -40,15 +40,15 @@ import java.util.Set; /** * Bootstrap core properties binder adapt. */ -public class SpringBoot15BootstrapConfigPropertiesBinderAdapt implements ApplicationContextAware, BootstrapConfigPropertiesBinderAdapt { +public class SpringBoot1xBootstrapConfigPropertiesBinderAdapt implements ApplicationContextAware, BootstrapConfigPropertiesBinderAdapt { private ApplicationContext applicationContext; /** * Bootstrap core properties binder. * - * @param configInfo - * @param bootstrapConfigProperties + * @param configInfo config info + * @param bootstrapConfigProperties bootstrap config properties * @return */ @Override @@ -56,20 +56,17 @@ public class SpringBoot15BootstrapConfigPropertiesBinderAdapt implements Applica BootstrapConfigProperties bindableCoreProperties = new BootstrapConfigProperties(); RelaxedNames relaxedNames = new RelaxedNames(BootstrapConfigProperties.PREFIX); Set names = getNames(bindableCoreProperties, relaxedNames); - // 绑定器 Map stringConfigInfo = new HashMap<>(configInfo.size()); configInfo.forEach((key, value) -> stringConfigInfo.put(key.toString(), value)); MapPropertySource test = new MapPropertySource("Hippo4j", stringConfigInfo); MutablePropertySources propertySources = new MutablePropertySources(); propertySources.addFirst(test); PropertyValues propertyValues = CustomPropertyNamePatternsMatcher.getPropertySourcesPropertyValues(names, propertySources); - RelaxedDataBinder dataBinder = new RelaxedDataBinder(bindableCoreProperties, BootstrapConfigProperties.PREFIX); dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE); dataBinder.setIgnoreNestedProperties(false); dataBinder.setIgnoreInvalidFields(false); dataBinder.setIgnoreUnknownFields(true); - ResourceEditorRegistrar resourceEditorRegistrar = new ResourceEditorRegistrar(applicationContext, applicationContext.getEnvironment()); resourceEditorRegistrar.registerCustomEditors(dataBinder); dataBinder.bind(propertyValues); diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java similarity index 88% rename from hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java rename to hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java index 39431a6f..edf29a0d 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-1.5-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/java/org/springframework/boot/bind/CustomPropertyNamePatternsMatcher.java @@ -18,24 +18,30 @@ package org.springframework.boot.bind; import org.springframework.beans.PropertyValues; -import org.springframework.boot.bind.DefaultPropertyNamePatternsMatcher; -import org.springframework.boot.bind.PropertyNamePatternsMatcher; -import org.springframework.boot.bind.PropertySourcesPropertyValues; import org.springframework.core.env.MutablePropertySources; import java.util.Set; +/** + * Custom property name patterns matcher. + */ public class CustomPropertyNamePatternsMatcher { private static final char[] EXACT_DELIMITERS = {'_', '.', '['}; + /** + * Get property sources property values. + * + * @param names + * @param propertySources + * @return + */ public static PropertyValues getPropertySourcesPropertyValues(Set names, MutablePropertySources propertySources) { PropertyNamePatternsMatcher includes = getPropertyNamePatternsMatcher(names); return new PropertySourcesPropertyValues(propertySources, names, includes, true); } private static PropertyNamePatternsMatcher getPropertyNamePatternsMatcher(Set names) { - return new DefaultPropertyNamePatternsMatcher(EXACT_DELIMITERS, true, names); } } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/resources/META-INF/spring.factories b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..2fcd64db --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-1x-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot1x.starter.config.ConfigHandlerAutoConfiguration diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java index 4ab2c09a..21fa48f4 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java @@ -118,5 +118,4 @@ public class ConfigHandlerConfiguration { return new PolarisRefresherHandler(configFileService); } } - } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 46bad601..783a2680 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -57,9 +57,9 @@ import org.springframework.core.annotation.Order; @Configuration @AllArgsConstructor @ConditionalOnBean(MarkerConfiguration.Marker.class) -@EnableConfigurationProperties(BootstrapConfigProperties.class) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") -@Import({ConfigHandlerConfiguration.class}) +@EnableConfigurationProperties(BootstrapConfigProperties.class) +@Import(ConfigHandlerConfiguration.class) @ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class, LocalLogMonitorConfiguration.class, MicrometerMonitorConfiguration.class}) public class DynamicThreadPoolAutoConfiguration { diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java index ea8c2eef..a3e410c7 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java @@ -25,7 +25,6 @@ import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import cn.hippo4j.config.springboot.starter.parser.ConfigParserHandler; import cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEvent; import cn.hippo4j.core.executor.support.ThreadPoolBuilder; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; @@ -71,8 +70,8 @@ public abstract class AbstractConfigThreadPoolDynamicRefresh if (CollectionUtil.isNotEmpty(newValueChangeMap)) { Optional.ofNullable(configInfo).ifPresent(each -> each.putAll(newValueChangeMap)); } - BootstrapConfigProperties bindableCoreProperties = bootstrapConfigPropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties); - ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, bindableCoreProperties)); + BootstrapConfigProperties binderCoreProperties = bootstrapConfigPropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties); + ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, binderCoreProperties)); } catch (Exception ex) { log.error("Hippo-4J core dynamic refresh failed.", ex); } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/BootstrapConfigPropertiesBinderAdapt.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/BootstrapConfigPropertiesBinderAdapt.java index 44bbca6b..1f8bf886 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/BootstrapConfigPropertiesBinderAdapt.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/BootstrapConfigPropertiesBinderAdapt.java @@ -21,7 +21,17 @@ import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import java.util.Map; +/** + * Bootstrap config properties binder adapt. + */ public interface BootstrapConfigPropertiesBinderAdapt { + /** + * Bootstrap core properties binder. + * + * @param configInfo dynamic thread pool configuration + * @param bootstrapConfigProperties bootstrap config properties + * @return + */ BootstrapConfigProperties bootstrapCorePropertiesBinder(Map configInfo, BootstrapConfigProperties bootstrapConfigProperties); } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/DefaultBootstrapConfigPropertiesBinderAdapt.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/DefaultBootstrapConfigPropertiesBinderAdapt.java index 1d4cd228..684d6aad 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/DefaultBootstrapConfigPropertiesBinderAdapt.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/DefaultBootstrapConfigPropertiesBinderAdapt.java @@ -43,5 +43,4 @@ public class DefaultBootstrapConfigPropertiesBinderAdapt implements BootstrapCon Binder binder = new Binder(sources); return binder.bind(BootstrapConfigProperties.PREFIX, Bindable.ofInstance(bootstrapConfigProperties)).get(); } - } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java index 5f0cbe25..63a245d1 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java @@ -31,9 +31,7 @@ import java.util.Map; import java.util.Objects; /** - * @author : wh - * @date : 2022/8/30 17:59 - * @description: + * Etcd refresher handler. */ @Slf4j public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { @@ -57,7 +55,6 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh Map etcd = bootstrapConfigProperties.getEtcd(); Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET)); initClient(etcd, charset); - String key = etcd.get(KEY); GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get(); KeyValue keyValue = getResponse.getKvs().get(0); @@ -70,8 +67,7 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh String key = etcd.get(KEY); Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET)); initClient(etcd, charset); - - // todo Currently only supports json + // TODO Currently only supports json GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get(); KeyValue keyValue = getResponse.getKvs().get(0); if (Objects.isNull(keyValue)) { @@ -111,7 +107,7 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh * @param charset charset */ private void initClient(Map etcd, Charset charset) { - // todo + // TODO if (Objects.isNull(client)) { String user = etcd.get(USER); String password = etcd.get(PASSWORD); @@ -123,5 +119,4 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh .build() : clientBuilder.build(); } } - } \ No newline at end of file diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java index 6f328b1f..0272aefb 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java @@ -32,6 +32,7 @@ import java.util.concurrent.Executor; public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { static final String DATA_ID = "data-id"; + static final String GROUP = "group"; private final NacosConfigManager nacosConfigManager; diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java index 0bde29a5..ba882bdb 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java @@ -17,7 +17,6 @@ package cn.hippo4j.config.springboot.starter.refresher; -import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import com.alibaba.cloud.nacos.NacosConfigProperties; import com.alibaba.nacos.api.annotation.NacosInjected; import com.alibaba.nacos.api.config.ConfigService; @@ -34,6 +33,7 @@ import java.util.concurrent.Executor; public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { static final String DATA_ID = "data-id"; + static final String GROUP = "group"; @NacosInjected diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java index 48d03fe4..e9ea9e72 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java @@ -29,9 +29,7 @@ import java.util.Map; import java.util.Objects; /** - *@author : wh - *@date : 2022/10/1 15:24 - *@description: + * Polaris refresher handler. */ @RequiredArgsConstructor public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { @@ -80,5 +78,4 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); } - } diff --git a/hippo4j-spring-boot/pom.xml b/hippo4j-spring-boot/pom.xml index 9e5d2a3c..475619f3 100644 --- a/hippo4j-spring-boot/pom.xml +++ b/hippo4j-spring-boot/pom.xml @@ -15,6 +15,6 @@ hippo4j-spring-boot-starter hippo4j-spring-boot-starter-adapter hippo4j-spring-boot-starter-monitor - hippo4j-config-spring-boot-1.5-starter + hippo4j-config-spring-boot-1x-starter