I want to be able to change properties if needed after an app has been deployed rather than change properties locally then repackage and deploy the app..
I have the following setup:
@Configuration
@EnableWebMvc
@PropertySource("classpath:application.properties")
@ComponentScan(basePackages = {"com.example"})
public class MyApp extends WebMvcConfigurerAdapter {
@Autowired
Environment env;
...
This works fine. But if I want to change the properties I have to re-package and deploy the app (WAR file), right? I've tried going into the exploded /tomcat/myapp/WEB-INF/classes/application.properties and making a change there, then re-running the app without redeploying it but it still seems to have the old settings.
I guess I could do something like the following, but it doesn't seem the Spring way to do things:
Properties loadProps = new Properties();
String value1 = null;
String value2 = null;
try {
String location = "/path/to/application.properties";
loadProps.load(new FileInputStream(location));
value1 = loadProps.getProperty("value1");
value2 = loadProps.getProperty("value2");
} catch (Exception e) {
System.out.println("Caught an exception when getting properties file");
e.printStackTrace();
}
..then load the properties object as a Spring bean or something.
Any suggestions on how this ought to be done in Spring MVC?