我对我的定制redis starter有一个依赖,它有一个配置类,我想在它之前启动它 RedissonAutoConfiguration
,为此,我使用 @AutoConfigureBefore
但是,它似乎不起作用而且仍然, RedissonAutoConfiguration
先开始。
唯一有效的办法似乎是增加 @ComponentScan(basePackage = "path_to_config")
,但我不想在这里使用任何注解,我想在开始之前就开始 RedissonAutoConfiguration
自己
我有 spring.factories
在我的redis starter文件中进行类自动配置
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
za.co.discovery.health.dhp.starter.redis.config.RedisClientConfiguration
package za.co.discovery.health.dhp.starter.redis.config;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import java.util.List;
@Configuration
@AutoConfigureBefore(RedissonAutoConfiguration.class)
public class RedisClientConfiguration {
@Profile("single-server-redis-client")
@Bean(destroyMethod = "shutdown")
public RedissonClient singleServerRedissonClient(@Value("${single-server.redis.client.host:localhost}") String redisClientHost, @Value("${single-server.redis.client.port:6379}") long redisClientPort) {
Config config = new Config();
config.useSingleServer().setAddress(String.format("redis://%s:%d", redisClientHost, redisClientPort));
return Redisson.create(config);
}
@Profile("cluster-redis-client")
@Bean(destroyMethod = "shutdown")
public RedissonClient clusterRedissonClient(@Value("${spring.redis.sentinel.nodes}") List<String> sentinelNodes, @Value("${spring.redis.sentinel.master}") String sentinelMaster, @Value("${spring.redis.sentinel.password}") String password) {
Config config = new Config();
config.useSentinelServers().setMasterName(sentinelMaster).setPassword(password);
sentinelNodes.forEach((sentinelNode) -> {
config.useSentinelServers().addSentinelAddress("redis://" + sentinelNode);
});
return Redisson.create(config);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!