我以前的配置像
spring.redis.host=192.168.1.1
现在我想修改
spring.redis.host=192.168.1.2
但不需要重新启动我的项目,我怎么做呢?
8oomwypt1#
好吧,我找到了答案:
RedisTemplate template = (RedisTemplate) applicationContext.getBean("redisTemplate"); JedisConnectionFactory redisConnectionFactory = (JedisConnectionFactory) template.getConnectionFactory(); //关闭连接池 redisConnectionFactory.destroy(); redisConnectionFactory.setShardInfo(null); redisConnectionFactory.setHostName(host); redisConnectionFactory.setPort(port); redisConnectionFactory.setPassword(password); redisConnectionFactory.setDatabase(database); //重新创建连接池 redisConnectionFactory.afterPropertiesSet(); template.setConnectionFactory(redisConnectionFactory);
1条答案
按热度按时间8oomwypt1#
好吧,我找到了答案: