使用NACOS作爲配置中心-redisson問題

不想使用 spring.redis.redisson.config=classpath:redisson.yaml 這種方式 搜索了好多 關於java:spring-cloud-採用nacos作爲註冊中心動態配置redisson

SpringBoot整合Redisson實戰(通過redisson-spring-boot-starter)

最後參考阿里雲的一個提問回覆驗證成功 使用NACOS作爲配置中心問題


spring.redis.redisson.config={"singleServerConfig": {"address": "redis://ip:port","subscriptionConnectionPoolSize": 1,"connectionMinimumIdleSize": 1,"connectionPoolSize": 1,"password": "password"}}

屬性值可以在:org.redisson.config.Config 類裏面看。

祝成功。

最後在自己的項目中配置redisson

@Configuration
@ComponentScan
public class RedissonConfiguration {

    @Value("${spring.redis.redisson.config}")
    private String redissonConfig;

    /**
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() throws IOException{
        Config config = Config.fromYAML(redissonConfig);
        config.setCodec(new JsonJacksonCodec());
        return Redisson.create(config);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章