disconf.xml
1、xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 使用disconf必须添加以下配置 --> <bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean" destroy-method="destroy"> <property name="scanPackage" value="com.dds.rss.route" /> </bean> <bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond" init-method="init" destroy-method="destroy"> </bean> <!-- 使用托管方式的disconf配置(无代码侵入, 配置更改会自动reload) --> <bean id="configproperties_disconf" class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean"> <property name="locations"> <list> <!--多个动态配置配置在这里--> <value>classpath:version.properties</value> </list> </property> </bean> <bean id="propertyConfigurer" class="com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer"> <property name="ignoreResourceNotFound" value="true" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="propertiesArray"> <list> <ref bean="configproperties_disconf" /> </list> </property> </bean> </beans>
2、应用属性配置
/**
* 描述: ID 属性
*
* @author 01374806
* @date 2018/10/2
*/
@DisconfFile(filename = "id.properties")
@Component
public class IdProperties {
private Long datacenterId = 0L;
@DisconfFileItem(name = "dds.rss.route.id.datacenterId", associateField = "datacenterId")
public Long getDatacenterId() {
return datacenterId;
}
public void setDatacenterId(Long datacenterId) {
this.datacenterId = datacenterId;
}
}
3、回调(消息通知配置)
@Slf4j @Component @DisconfUpdateService(confFileKeys = { "dispatch.properties" }) public class DispatchPropertiesCallback implements IDisconfUpdate { @Override public void reload() throws Exception { log.info("dispatch.properties 检测到更新"); } }