This issue proposes the introduction of RefreshScope, allowing for auto-proxying selected beans at start up and allowing them to be refreshed at runtime
Here is a prototype (Maven project with test cases): https://gist.github.com/759898.
Spring beans in scope="refresh" are re-initialized on the next method call after a refresh.
Example (from unit test):
<bean class="org.springframework.context.refresh.RefreshScope" />
<bean id="service" class="org.springframework.context.refresh.RefreshScopeIntegrationTests$ExampleService" scope="refresh">
<property name="message" value="#
<property name="delay" value="#
<entry key="message" value="Hello scope!"/>
<entry key="delay" value="0"/>
The "service" bean is initialized only when a method is first called (standard scoped proxy), but can be re-instantiated by calling RefreshScope.refresh() and (in this case) changing the values in the map.
The implementation tries to be careful about DisposableBeans, but there are probably still openings for problems during a refresh if the destroy() method of the scoped bean changes some state that other components are relying on. It still seems useful enough as it is to me (in fact I'm using it already), and if you steer clear of DisposableBean it should be fine. Maybe we should just not support DisposableBean (or anything with a destruction callback)?