environment properties are there in application.properties
application.properties
app.mail.allowedDomains=gmail
in class
@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"));
}
Output
Inside impl
@Value: null
@Value: null
Env: gmail
It is not even setting "nothing"(default value if not found) in 2nd scenario. But from env it's printing
I even tried with @ConfigurationProperties in main class of package.
No success.
Is value fetched from env file on each hit or on app load only it will load?
Value from org.springframework.beans.factory.annotation.Value