可以写一个配置类 package com.example.springboot.tool; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import java.io.IOException; /** * @Auther: Java小强 * @Date: 2022/1/28 - 10:29 * @Decsription: com.example.springboot.tool * @Version: 1.0 */ @Configuration public class InitializingRedis{ @Bean public RedissonClient getRedissonClient() throws IOException { ResourceLoader loader = new DefaultResourceLoader(); Resource resource = loader.getResource("classpath:redisson.yml"); Config config = Config.fromYAML(resource.getInputStream()); config.useClusterServers(); return Redisson.create(config); } }
可以写一个配置类 package com.example.springboot.tool; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import java.io.IOException; /** * @Auther: Java小强 * @Date: 2022/1/28 - 10:29 * @Decsription: com.example.springboot.tool * @Version: 1.0 */ @Configuration public class InitializingRedis{ @Bean public RedissonClient getRedissonClient() throws IOException { ResourceLoader loader = new DefaultResourceLoader(); Resource resource = loader.getResource("classpath:redisson.yml"); Config config = Config.fromYAML(resource.getInputStream()); config.useClusterServers(); return Redisson.create(config); } }