实现方法:
一、类上添加注解
@Component
二、定义静态成员变量
private static String redisUrl;
private static String redisPort;
private static String redisPassword;
三、增加非静态的setter方法
@Value("${redis.url}")
public void setRedisUrl(String redisUrl) {
JedisTool.redisUrl = redisUrl;
}
@Value("${redis.port}")
public void setRedisPort(String redisPort) {
JedisTool.redisPort = redisPort;
}
@Value("${redis.password}")
public void setRedisPassword(String redisPassword) {
JedisTool.redisPassword = redisPassword;
}
要用setter