首页 > 解决方案 > How to using annotation @RefreshScope with spingboot : connectionFactory?

问题描述

how to refresh connectionFactory or connectionpool,such as dataSource,JedisConnectionFactory... when the springboot application is running? (I used springcould-config to update my configs)

@Bean
@ConfigurationProperties(prefix = "spring.redis.pool")
public JedisPoolConfig getRedisConfig() {
    JedisPoolConfig config = new JedisPoolConfig();
    return config;
}

@Bean(name = "redisConnection")
public JedisConnectionFactory getConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    JedisPoolConfig config = getRedisConfig();
    factory.setPoolConfig(config);
    factory.setPassword(password);
    factory.setHostName(hostName);
    factory.setPort(port);
    factory.setDatabase(database);
    return factory;
}

...

pseudocode:

onChangeListener function then

refreshScope.refresh("redisConnection");

but it does not work,however, some files with @Value("${spring.redis.host}") it change

标签: spring-bootspring-cloud

解决方案


推荐阅读