Fix problem when update fizz config dynamically
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.fizzgate.beans.factory.config;
|
||||
|
||||
import com.fizzgate.config.FizzConfigConfiguration;
|
||||
import com.fizzgate.context.config.annotation.FizzRefreshScope;
|
||||
import com.fizzgate.util.Consts;
|
||||
import com.fizzgate.util.JacksonUtils;
|
||||
@@ -35,6 +36,8 @@ import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -69,6 +72,11 @@ public class FizzBeanFactoryPostProcessor implements BeanFactoryPostProcessor, E
|
||||
if (fizzConfigEnable.equals(Consts.S.TRUE)) {
|
||||
// initReactiveStringRedisTemplate();
|
||||
// initFizzPropertySource();
|
||||
|
||||
Map<String, Object> sources = FizzEnvironmentPostProcessor.getSources();
|
||||
MapPropertySource fizzPropertySource = new MapPropertySource(FizzConfigConfiguration.PROPERTY_SOURCE + "AfterBeanFactory", sources);
|
||||
environment.getPropertySources().addFirst(fizzPropertySource);
|
||||
|
||||
initBeanProperty2beanMap(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.boot.logging.DeferredLog;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.SmartApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
@@ -34,18 +35,28 @@ import java.util.Map;
|
||||
* @author hongqiaowei
|
||||
*/
|
||||
|
||||
public class FizzEnvironmentPostProcessor implements EnvironmentPostProcessor, SmartApplicationListener {
|
||||
public class FizzEnvironmentPostProcessor implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
|
||||
|
||||
private static final DeferredLog LOGGER = new DeferredLog();
|
||||
|
||||
private static Logger LOG = null;
|
||||
|
||||
private static final Map<String, Object> sources = new HashMap<>();
|
||||
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||
|
||||
|
||||
protected static Map<String, Object> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
String fizzConfigEnable = environment.getProperty("fizz.config.enable", Consts.S.TRUE);
|
||||
@@ -84,8 +95,7 @@ public class FizzEnvironmentPostProcessor implements EnvironmentPostProcessor, S
|
||||
|
||||
private void initFizzPropertySource() {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> sources = new HashMap<>();
|
||||
MapPropertySource fizzPropertySource = new MapPropertySource(FizzConfigConfiguration.PROPERTY_SOURCE, sources);
|
||||
MapPropertySource fizzPropertySource = new MapPropertySource(FizzConfigConfiguration.PROPERTY_SOURCE + "AfterEnv", sources);
|
||||
propertySources.addFirst(fizzPropertySource);
|
||||
|
||||
Result<?> result = Result.succ();
|
||||
|
||||
Reference in New Issue
Block a user