INT激活和int ForgotPassword的作品不錯,但字符串變量返回null我需要的AppSettings靜態類@PropertySource @Value靜態字符串返回null
@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;
}
}
的.properties
Activation=0
ForgotPassword=1
CryptoSplit=:OSK:
CryptoKey=TheBestSecretKey
寫setter方法,把'@ Value'上setter方法,而不是放置變量 – pvpkiran
您不能在'static'字段/方法上自動連線或使用'@ Value'。 –
如果你想使用值註釋定義一個靜態變量請看[這個答案](https://stackoverflow.com/a/45192557/3493036) – Patrick