parent
e155866ad1
commit
2d3144a9bc
@ -0,0 +1,41 @@ |
|||||||
|
package com.gitee.sop.openapi.config; |
||||||
|
|
||||||
|
import com.ctrip.framework.apollo.Config; |
||||||
|
import com.ctrip.framework.apollo.ConfigService; |
||||||
|
import com.ctrip.framework.apollo.model.ConfigChange; |
||||||
|
import com.ctrip.framework.apollo.model.ConfigChangeEvent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.annotation.PostConstruct; |
||||||
|
|
||||||
|
/*** |
||||||
|
* |
||||||
|
* @author wangping created on 2020/11/5 16:06 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Component |
||||||
|
public class ApolloApplicationConfig implements BeanPostProcessor { |
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct |
||||||
|
public void init() { |
||||||
|
loadApplication(); |
||||||
|
} |
||||||
|
|
||||||
|
private void loadApplication() { |
||||||
|
Config config = ConfigService.getAppConfig(); |
||||||
|
config.addChangeListener(this::getChangedEvent); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void getChangedEvent(ConfigChangeEvent changeEvent) { |
||||||
|
for (String key : changeEvent.changedKeys()) { |
||||||
|
ConfigChange change = changeEvent.getChange(key); |
||||||
|
log.info("Found change - key: {}, oldValue: {}, newValue: {}, changeType:{}", |
||||||
|
change.getPropertyName(), change.getOldValue(), |
||||||
|
change.getNewValue(), change.getChangeType()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,2 @@ |
|||||||
|
app.id=open-apis |
||||||
|
jdkVersion=1.8 |
Loading…
Reference in new issue