spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.55k stars 40.54k forks source link

Reloading properties files (or maybe the whole context) #1170

Closed dickerpulli closed 9 years ago

dickerpulli commented 10 years ago

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.

dsyer commented 10 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.

dickerpulli commented 10 years ago

You mean, I call context.close() and after that SpringApplication.run(...)?

dsyer commented 10 years ago

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.

dickerpulli commented 10 years ago

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 ...

dsyer commented 10 years ago

I have it working as an MVC endpoint. Should be released sometime this summer (SpringOne is September).

dickerpulli commented 10 years ago

Can I take a look at your code? Is there a public link, i.e. at github?

dsyer commented 10 years ago

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.

sunaina-ishi commented 9 years ago

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.

dsyer commented 9 years ago

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).

sunaina-ishi commented 9 years ago

Thanks a lot for your reply. It worked.

sunaina-ishi commented 9 years ago

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

dsyer commented 9 years ago

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.