http://cloud.spring.io/spring-cloud-static/Dalston.SR5/single/spring-cloud.html#_reactive_programming_support 17/289
refresh, and where you need a change to be atomic over the whole ApplicationContext . To address those concerns we have
@RefreshScope .
2.8 Refresh Scope
A Spring @Bean that is marked as @RefreshScope will get special treatment when there is a configuration change. This addresses the
problem of stateful beans that only get their configuration injected when they are initialized. For instance if a DataSource has open
connections when the database URL is changed via the Environment , we probably want the holders of those connections to be able to
complete what they are doing. Then the next time someone borrows a connection from the pool he gets one with the new URL.
Refresh scope beans are lazy proxies that initialize when they are used (i.e. 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 just need to invalidate its cache entry.
The RefreshScope is a bean in the context and it has a public method refreshAll() to refresh all beans in the scope by clearing the target
cache. There is also a refresh(String) method to refresh an individual bean by name. This functionality is exposed in the /refresh
endpoint (over HTTP or JMX).
@RefreshScope works (technically) on an @Configuration class, but it might lead to surprising behaviour: e.g. it does not
mean that all the @Beans defined in that class are themselves @RefreshScope . Specifically, anything that depends on those
beans cannot rely on them being updated when a refresh is initiated, unless it is itself in @RefreshScope (in which it will be
rebuilt on a refresh and its dependencies re-injected, at which point they will be re-initialized from the refreshed
@Configuration ).
2.9 Encryption and Decryption
Spring Cloud has an Environment pre-processor for decrypting property values locally. It follows the same rules as the Config Server, and
has the same external configuration via encrypt.* . Thus you can use encrypted values in the form {cipher}* and as long as there is a
valid key then they will be decrypted before the main application context gets the Environment . To use the encryption features in an
application you need to include Spring Security RSA in your classpath (Maven co-ordinates "org.springframework.security:spring-security-rsa")
and you also need the full strength JCE extensions in your JVM.
If you are getting an exception due to "Illegal key size" and you are using Sun’s JDK, you need to install the Java Cryptography Extension
(JCE) Unlimited Strength Jurisdiction Policy Files. See the following links for more information:
Java 6 JCE
Java 7 JCE
Java 8 JCE
Extract files into JDK/jre/lib/security folder (whichever version of JRE/JDK x64/x86 you are using).
2.10 Endpoints
For a Spring Boot Actuator application there are some additional management endpoints:
POST to /env to update the Environment and rebind @ConfigurationProperties and log levels
/refresh for re-loading the boot strap context and refreshing the @RefreshScope beans
/restart for closing the ApplicationContext and restarting it (disabled by default)
/pause and /resume for calling the Lifecycle methods ( stop() and start() on the ApplicationContext )
3. Spring Cloud Commons: Common Abstractions
Patterns such as service discovery, load balancing and circuit breakers lend themselves to a common abstraction layer that can be consumed
by all Spring Cloud clients, independent of the implementation (e.g. discovery via Eureka or Consul).
3.1 @EnableDiscoveryClient
Commons provides the @EnableDiscoveryClient annotation. This looks for implementations of the DiscoveryClient interface via
META-INF/spring.factories . Implementations of Discovery Client will add a configuration class to spring.factories under the
org.springframework.cloud.client.discovery.EnableDiscoveryClient key. Examples of DiscoveryClient implementations: are
Spring Cloud Netflix Eureka, Spring Cloud Consul Discovery and Spring Cloud Zookeeper Discovery.