【发布时间】:2017-09-14 12:23:57
【问题描述】:
int Activation 和 int ForgotPassword 效果很好,但字符串变量返回 null 我需要 AppSettings 的静态类
@PropertySource("classpath:appSettings.properties")
public class AppSettings {
@Value("${Activation}")
private static int Activation;
@Value("${ForgotPassword}")
private static int ForgotPassword;
@Value("${CryptoSplit}")
private static String CryptoSplit;
@Value("${CryptoKey}")
private static String CryptoKey;
public static String getCryptoSplit() {
return CryptoSplit;
}
public static String getCryptoKey() {
return CryptoKey;
}
public static int getActivation() {
return Activation;
}
public static int getForgotPassword() {
return ForgotPassword;
}
}
.属性
Activation=0
ForgotPassword=1
CryptoSplit=:OSK:
CryptoKey=TheBestSecretKey
【问题讨论】:
-
编写setter方法并将
@Value放在setter方法上,而不是放在变量上 -
您不能在
static字段/方法上自动连接或使用@Value。 -
如果您想使用值注释定义静态变量,请查看this answer
标签: java spring spring-boot properties appsettings