Sync docs from master to gh-pages
This commit is contained in:
@@ -67,7 +67,11 @@ Re-binding <code class="literal">@ConfigurationProperties</code> does not cover
|
||||
To address those concerns, we have <code class="literal">@RefreshScope</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_refresh_scope" href="#_refresh_scope"></a>1.8 Refresh Scope</h2></div></div></div><p>When there is a configuration change, a Spring <code class="literal">@Bean</code> that is marked as <code class="literal">@RefreshScope</code> gets special treatment.
|
||||
This feature addresses the problem of stateful beans that only get their configuration injected when they are initialized.
|
||||
For instance, if a <code class="literal">DataSource</code> has open connections when the database URL is changed via the <code class="literal">Environment</code>, you probably want the holders of those connections to be able to complete what they are doing.
|
||||
Then, the next time something borrows a connection from the pool, it gets one with the new URL.</p><p>Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values.
|
||||
Then, the next time something borrows a connection from the pool, it gets one with the new URL.</p><p>Sometimes, it might even be mandatory to apply the <code class="literal">@RefreshScope</code>
|
||||
annotation on some beans which can be only initialized once. If a bean
|
||||
is "immutable", you will have to either annotate the bean with <code class="literal">@RefreshScope</code>
|
||||
or specify the classname under the property key
|
||||
<code class="literal">spring.cloud.refresh.extra-refreshable</code>.</p><p>Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values.
|
||||
To force a bean to re-initialize on the next method call, you must invalidate its cache entry.</p><p>The <code class="literal">RefreshScope</code> is a bean in the context and has a public <code class="literal">refreshAll()</code> method to refresh all beans in the scope by clearing the target cache.
|
||||
The <code class="literal">/refresh</code> endpoint exposes this functionality (over HTTP or JMX).
|
||||
To refresh an individual bean by name, there is also a <code class="literal">refresh(String)</code> method.</p><p>To expose the <code class="literal">/refresh</code> endpoint, you need to add following configuration to your application:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">management</span>:
|
||||
|
||||
Reference in New Issue
Block a user