I have a Spring boot Web application. The application is configured via java classes using the @Configurable annotation. I have introduced two profiles: \'i
You can't just refresh an existing context. You have to close the old one and create a new one. You can see how we do it in Spring Cloud here: https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-context/src/main/java/org/springframework/cloud/context/restart/RestartEndpoint.java. If you want to you can include that Endpoint
just by adding spring-cloud-context as a dependency, or you can copy the code I guess and use it in your own "endpoint".
Here's the endpoint implementation (some details missing in fields):
@ManagedOperation
public synchronized ConfigurableApplicationContext restart() {
if (this.context != null) {
if (this.integrationShutdown != null) {
this.integrationShutdown.stop(this.timeout);
}
this.application.setEnvironment(this.context.getEnvironment());
this.context.close();
overrideClassLoaderForRestart();
this.context = this.application.run(this.args);
}
return this.context;
}