diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml
index 54ebf34e..58f70c86 100644
--- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml
@@ -54,6 +54,15 @@
2.2.5.RELEASE
true
+
+
+ com.ctrip.framework.apollo
+ apollo-client
+ ${apollo.version}
+ compile
+ true
+
+
diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/BootstrapCoreProperties.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/BootstrapCoreProperties.java
index bd7233b5..2076a075 100644
--- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/BootstrapCoreProperties.java
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/BootstrapCoreProperties.java
@@ -1,5 +1,6 @@
package cn.hippo4j.core.starter.config;
+import cn.hippo4j.core.starter.parser.ConfigFileTypeEnum;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -38,7 +39,7 @@ public class BootstrapCoreProperties {
/**
* Config file type.
*/
- private String configFileType;
+ private ConfigFileTypeEnum configFileType;
/**
* Nacos config.
diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/DynamicThreadPoolCoreAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/DynamicThreadPoolCoreAutoConfiguration.java
index dc5aba1d..8bca08ff 100644
--- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/DynamicThreadPoolCoreAutoConfiguration.java
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/config/DynamicThreadPoolCoreAutoConfiguration.java
@@ -12,18 +12,17 @@ import cn.hippo4j.common.notify.platform.WeChatSendMessageHandler;
import cn.hippo4j.core.config.UtilAutoConfiguration;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.starter.notify.CoreNotifyConfigBuilder;
+import cn.hippo4j.core.starter.parser.ConfigParserHandler;
+import cn.hippo4j.core.starter.refresher.ApolloRefresherHandler;
import cn.hippo4j.core.starter.refresher.NacosCloudRefresherHandler;
import cn.hippo4j.core.starter.refresher.NacosRefresherHandler;
-import cn.hippo4j.core.starter.refresher.config.ConfigParser;
-import cn.hippo4j.core.starter.refresher.config.impl.PropConfigParser;
-import cn.hippo4j.core.starter.refresher.config.impl.YmlConfigParser;
import cn.hippo4j.core.starter.support.DynamicThreadPoolPostProcessor;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
-import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -31,8 +30,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
-import java.util.List;
-
/**
* Dynamic thread pool auto configuration.
*
@@ -51,8 +48,7 @@ public class DynamicThreadPoolCoreAutoConfiguration {
private static final String NACOS_CONFIG_KEY = "com.alibaba.nacos.api.config";
- private final List yamlList = Lists.newArrayList("yaml", "yml");
- private final List propList = Lists.newArrayList("properties");
+ private static final String APOLLO_CONFIG_KEY = "com.ctrip.framework.apollo.ConfigService.class";
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
@@ -106,32 +102,25 @@ public class DynamicThreadPoolCoreAutoConfiguration {
@ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY)
public NacosRefresherHandler nacosRefresherHandler(ConfigService configService,
ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler,
- ConfigParser configParser,
BootstrapCoreProperties bootstrapCoreProperties) {
- return new NacosRefresherHandler(configService, threadPoolNotifyAlarmHandler, configParser, bootstrapCoreProperties);
+ return new NacosRefresherHandler(configService, threadPoolNotifyAlarmHandler, bootstrapCoreProperties);
}
@Bean
@ConditionalOnClass(name = NACOS_CONFIG_MANAGER_KEY)
public NacosCloudRefresherHandler nacosCloudRefresherHandler(NacosConfigManager nacosConfigManager,
ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler,
- ConfigParser configParser,
BootstrapCoreProperties bootstrapCoreProperties) {
- return new NacosCloudRefresherHandler(nacosConfigManager, threadPoolNotifyAlarmHandler, configParser, bootstrapCoreProperties);
+ return new NacosCloudRefresherHandler(nacosConfigManager, threadPoolNotifyAlarmHandler, bootstrapCoreProperties);
}
@Bean
- public ConfigParser configParserHandler() {
- // return new ConfigParserHandler();
- String configFileType = bootstrapCoreProperties.getConfigFileType();
- if (yamlList.contains(configFileType)) {
- return new YmlConfigParser();
- }
- if (propList.contains(configFileType)) {
- return new PropConfigParser();
- }
-
- throw new UnsupportedOperationException("暂不支持的配置文件类型: " + configFileType);
+ @ConditionalOnMissingBean
+ @ConditionalOnClass(name = APOLLO_CONFIG_KEY)
+ public ApolloRefresherHandler apolloRefresher(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler,
+ BootstrapCoreProperties bootstrapCoreProperties) {
+ return new ApolloRefresherHandler(threadPoolNotifyAlarmHandler, bootstrapCoreProperties);
}
+
}
diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/AbstractConfigParser.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/AbstractConfigParser.java
new file mode 100644
index 00000000..9664243d
--- /dev/null
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/AbstractConfigParser.java
@@ -0,0 +1,15 @@
+package cn.hippo4j.core.starter.parser;
+
+/**
+ * @author : wh
+ * @date : 2022/3/1 07:50
+ * @description:
+ */
+public abstract class AbstractConfigParser implements ConfigParser{
+
+ @Override
+ public boolean supports(ConfigFileTypeEnum type) {
+ return getConfigFileTypes().contains(type);
+ }
+
+}
diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigFileTypeEnum.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigFileTypeEnum.java
new file mode 100644
index 00000000..cba9c46d
--- /dev/null
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigFileTypeEnum.java
@@ -0,0 +1,35 @@
+package cn.hippo4j.core.starter.parser;
+
+import lombok.Getter;
+
+/**
+ * @author : wh
+ * @date : 2022/3/1 07:47
+ * @description:
+ */
+@Getter
+public enum ConfigFileTypeEnum {
+
+ PROPERTIES("properties"),
+ XML("xml"),
+ JSON("json"),
+ YML("yml"),
+ YAML("yaml"),
+ TXT("txt");
+
+ private final String value;
+
+ ConfigFileTypeEnum(String value) {
+ this.value = value;
+ }
+
+ public static ConfigFileTypeEnum of(String value) {
+ for (ConfigFileTypeEnum typeEnum : ConfigFileTypeEnum.values()) {
+ if (typeEnum.value.equals(value)) {
+ return typeEnum;
+ }
+ }
+ return PROPERTIES;
+ }
+
+}
diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigParser.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigParser.java
new file mode 100644
index 00000000..b692e6ca
--- /dev/null
+++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/parser/ConfigParser.java
@@ -0,0 +1,20 @@
+package cn.hippo4j.core.starter.parser;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author : wh
+ * @date : 2022/3/1 07:47
+ * @description:
+ */
+public interface ConfigParser {
+
+ boolean supports(ConfigFileTypeEnum type);
+
+ Map