Closed dickerpulli closed 9 years ago
You can call close() and that create a new one though. I'm working on something to do that, and also some hot-reload features just for the application.properties.
You mean, I call context.close() and after that SpringApplication.run(...)?
Yes. Here's some code that I tested and have working in my prototype:
public synchronized ConfigurableApplicationContext restart() {
if (context != null) {
context.close();
overrideClassLoaderForRestart();
context = application.run(args);
}
return context;
}
The class loader thing is just resetting the thread context classloader. If you are an embedded webapp you need to run all of that in a non-daemon thread to avoid the JVM exiting before it gets a chance to start the server again.
This is no what I want. because I want to have a Controller (WebMVC), that receives a "refresh-request" and performs the refresh of the application context.
I think, I wait for your feature to be released. Is it possible to give a forecast of the release date? Just approx ...
I have it working as an MVC endpoint. Should be released sometime this summer (SpringOne is September).
Can I take a look at your code? Is there a public link, i.e. at github?
Not yet. It's the usual thing with names. We don't have a name for it yet so we don't want to put links in the public domain that will break later. If you email me I can send you a preview.
Is the feature implemented to support the functionality as stated above to a Controller (WebMVC), that receives a "refresh-request" and performs the refresh of the application context.?. I have the sam e requirements.
You need the spring-cloud-context library. Adding it as a dependency, plus the spring-boot-actuator will activate a /refresh and a /restart endpoint (amongst other things).
Thanks a lot for your reply. It worked.
It seems to make it work adding @RefreshScope to the appropriate bean is necessary. Is this mandatory. Suppose I am writing a SMPP implementation and its properties are bind with a bean in our @Configuration file. I would like to change one of the properties of smpp server. Now I cannot add @RefreshScope SMPP APi's bundled in jar. So will the properties take affect after invoking refresh. Please suggest
It depends. The @RefreshScope
is needed for anything that needs to be re-initialized (as opposed to just rebound to the Environment
). This should be clear from the Spring Cloud user guide.
Is it possible to reload i.e. the application.properties file while running the application with out restarting the JVM?
I tried to call refresh() on the EmbeddedWebApplicationContext, but this class is no able to refresh more than once.