0

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?

Martyn
  • 6,031
  • 12
  • 55
  • 121
  • You're mixing two very different concepts, hot reloading and externalized configuration. Hot reloading is close to impossible to do cleanly; externalized configuration is trivially supported in Spring Boot. – chrylis -cautiouslyoptimistic- Jun 05 '19 at 14:29
  • check out this [answer](https://stackoverflow.com/questions/41830024/load-configuration-files-dynamically-using-spring/41830361#41830361) – Essex Boy Jun 05 '19 at 14:45

0 Answers0