码迷,mamicode.com
首页 > 其他好文 > 详细

disconf的简单使用与远程配置更改为使用本地配置

时间:2019-11-25 20:12:24      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:private   sentinel   prope   pts   this   ble   出现   shard   直接   

这几天因为阿里云迁移到腾讯云的原因,原来服务器上的disconf不再使用了。在这段时间里,系统出现的bug很难寻找原因(项目起不来),现在想要把disconf远程配置更改成直接使用本地配置。首先,了解一下disconf的使用:看官方文档,前两节就差不多了

disconf官方文档:https://disconf.readthedocs.io/zh_CN/latest/

你可以从上面的链接中另外打开一个窗口,方便阅读。从官方文档可以看出,远程配置更改为本地配置基本不需要改动什么代码,只需要将下面属性设置为false即可disconf.enable.remote.conf=false。很简单。

而我在启动时初始化redis没有读取到redis配置文件,也可以使用下面的方法来使用Spring的Bean从配置中注入值到实体类中:

redis.properties

sharded.redis.hosts=10.202.114.65:9156,10.202.114.65:9157,10.202.114.65:9158
sharded.redis.masters=ISS
sharded.redis.type=SENTINEL
sharded.redis.password=

spring配置文件中增加一个bean:

<bean id="redisSettings" class="com.sf.dds.znfj.config.RedisSettings">
  <property name="shardedHosts" value="${sharded.redis.hosts}" />
  <property name="shardedPassword" value="${sharded.redis.password}" />
  <property name="connectionTimeout" value="${redis.connectionTimeout}" />
  <property name="soTimeout" value="${redis.soTimeout}" />
  <property name="maxAttempts" value="${redis.maxAttempts}" />
</bean>

RedisSettings:

@Service
@DisconfFile(filename = "redis.properties")
public class RedisSettings {

    private int connectionTimeout;

    private int soTimeout;

    private int maxAttempts;

    private String sortPassword;

    private String shardedPassword;

    @DisconfFileItem(name = "sharded.redis.hosts", associateField = "shardedHosts")
    public String getShardedHosts() {
        return shardedHosts;
    }

    public void setShardedHosts(String shardedHosts) {
        this.shardedHosts = shardedHosts;
    }
    //省略其他set/get
}

disconf的简单使用与远程配置更改为使用本地配置

标签:private   sentinel   prope   pts   this   ble   出现   shard   直接   

原文地址:https://www.cnblogs.com/sean-zeng/p/11929851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!