工具類:
@Component
public class RedisUtils implements InitializingBean{
// Redis服務器IP
public static String IP;
// Redis的端口號
public static int PORT;
// 訪問密碼
public static String AUTH;
// Redis的節點
public static String INDEX;
@Value("${host}")
private String ip;
@Value("${port}")
private int port;
@Value("${password}")
private String auth;
@Value("${index}")
private String index;
@Override
public void afterPropertiesSet() throws Exception {
try {
IP = ip;
PORT = port;
AUTH = auth;
INDEX = index;
//......
} catch (Exception e) {
e.printStackTrace();
}
}
}
application.properties
host=127.0.0.1
port=21822
password=123456
index=0