application.properties中有环境属性
application.properties
app.mail.allowedDomains=gmail
课堂上
@Autowired
private Environment env;
@Value("${app.mail.allowedDomains}")
private static String allowedDomainsForMail;
@Value("${app.mail.allowedDomains:nothing}")
private static String allowedDomainsForMail2;
public void printProperties() {
System.out.println("Inside impl");
System.out.println("@Value:\t" + allowedDomainsForMail);
System.out.println("@Value:\t" + allowedDomainsForMail2);
System.out.println("Env:\t" + env.getProperty("app.mail.allowedDomains"));
}
输出
内部展示
@Value: null
@Value: null
Env: gmail
在第二种情况下甚至都没有设置“ nothing”(如果未找到,则为默认值)。但是从env开始打印
我什至在包的主类中尝试使用@ConfigurationProperties。
没有成功。
在每次匹配或应用加载时,是否仅从环境文件中获取值才能加载?
来自org.springframework.beans.factory.annotation.Value的值