I have a spring boot application and I want to read some variable from my application.properties file. In fact below codes do that. But I think there is a good
I have created following class
@Configuration
public class ConfigUtility {
@Autowired
private Environment env;
public String getProperty(String pPropertyKey) {
return env.getProperty(pPropertyKey);
}
}
and called as follow to get application.properties value
@Autowired
private ConfigUtility configUtil;
public AppResponse getDetails() {
AppResponse response = new AppResponse();
String email = configUtil.getProperty("emailid");
return response;
}
emailid=sunny@domain.com
unit tested, working as expected...