1、disconf.properties
disconf.enable.remote.conf=true
disconf.conf_server_host=disconf.xxx.com
disconf.version=1_0_0_0
disconf.app=app1
disconf.env=rd
disconf.ignore=
disconf.conf_server_url_retry_times=1
disconf.conf_server_url_retry_sleep_seconds=1
disconf.user_define_download_dir=./config
2、disconf.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" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 使用disconf必须添加以下配置 -->
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
destroy-method="destroy">
<!-- 扫描自己项目配置所在的包 -->
<property name="scanPackage" value="com.xxx.config"/>
</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*:app.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>
3、Application启动文件
@SpringBootApplication
@ImportResource({ "classpath:disconf.xml" })
@EnableConfigurationProperties
public class Application
{
public static void main(String[] args) throws Exception
{
SpringApplication.run(Application.class, args);
}
}
4、AppConfig文件
package com.vipabc.cpimsapi.config;
import com.baidu.disconf.client.common.annotations.DisconfFile;
import com.baidu.disconf.client.common.annotations.DisconfFileItem;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Configuration
@DisconfFile(filename = "app.properties")
public class AppConfig {
/**
* 请求外部链接超时时间
*/
private Integer urlConnectionTimeout;
@DisconfFileItem(name = "app.url_connection_timeout", associateField = "urlConnectionTimeout")
public Integer getUrlConnectionTimeout() {
return urlConnectionTimeout;
}
public void setUrlConnectionTimeout(Integer urlConnectionTimeout) {
this.urlConnectionTimeout = urlConnectionTimeout;
}
}
5、app.properties
app.url_connection_timeout=5000