原项目中的netty是这个版本的
引入redission依赖
然后由于项目中已经写好redis配置文件
在RedissionConfig配置类中直接复制粘贴集群
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;
@Configuration
public class RedissonConfig {
@Value("${redis.auth}")
private String password;
@Value("${cluster.host1}")
private String host1;
@Value("${cluster.host2}")
private String host2;
@Value("${cluster.host3}")
private String host3;
@Value("${cluster.host4}")
private String host4;
@Value("${cluster.host5}")
private String host5;
@Value("${cluster.host6}")
private String host6;
@Value("${cluster.port1}")
private String port1;
@Value("${cluster.port2}")
private String port2;
@Value("${cluster.port3}")
private String port3;
@Value("${cluster.port4}")
private String port4;
@Value("${cluster.port5}")
private String port5;
@Value("${cluster.port6}")
private String port6;
@Bean
public RedissonClient redissonClient(){
// 配置
Config config = new Config();
// 集群模式
config.useClusterServers().addNodeAddress("redis://"+host1+":"+port1)
.addNodeAddress("redis://"+host2+":"+port2)
.addNodeAddress("redis://"+host3+":"+port3)
.addNodeAddress("redis://"+host4+":"+port4)
.addNodeAddress("redis://"+host5+":"+port5)
.addNodeAddress("redis://"+host6+":"+port6)
.setPassword(password);
// 创建RedissonClient对象
return Redisson.create(config);
}
}
如果不配置密码的话,启动项目会报错
2024-02-22 13:49:07.375 WARN [XmlWebApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘partyBoService’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘repairDataService’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘repairUtil’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyInfoBaseService’: Unsatisfied dependency expressed through field ‘partyService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyService’: Unsatisfied dependency expressed through field ‘partyCompanyService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyCompanyService’: Unsatisfied dependency expressed through field ‘partyCompanyBoService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyCompanyBoService’: Unsatisfied dependency expressed through field ‘partyLogBoService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyLogBoService’: Unsatisfied dependency expressed through field ‘partyPersonnelBoService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘partyPersonnelBoService’: Unsatisfied dependency expressed through field ‘redissonClient’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘redissonClient’ defined in com.axatp.party.config.RedissonConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method ‘redissonClient’ threw exception; nested exception is org.redisson.client.RedisConnectionException: Can’t connect to servers!
接下来就是业务层的引入
最后在finally块中释放锁