You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
http://pivotal.io/platform-as-a-service/migrating-to-cloud-native-application-architectures-ebook[Cloud Native] is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development. A related discipline is that of building http://12factor.net/[12-factor Apps] in which development practices are aligned with delivery and operations goals, for instance by using declarative programming and management and monitoring. Spring Cloud facilitates these styles of development in a number of specific ways and the starting point is a set of features that all components in a distributed system either need or need easy access to when required.
6
+
http://pivotal.io/platform-as-a-service/migrating-to-cloud-native-application-architectures-ebook[Cloud Native] is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development.
7
+
A related discipline is that of building http://12factor.net/[12-factor Applications], in which development practices are aligned with delivery and operations goals -- for instance, by using declarative programming and management and monitoring.
8
+
Spring Cloud facilitates these styles of development in a number of specific ways.
9
+
The starting point is a set of features to which all components in a distributed system need easy access.
7
10
8
-
Many of those features are covered by http://projects.spring.io/spring-boot[Spring Boot], which we build on in Spring Cloud. Some more are delivered by Spring Cloud as two libraries: Spring Cloud Context and Spring Cloud Commons. Spring Cloud Context provides utilities and special services for the `ApplicationContext` of a Spring Cloud application (bootstrap context, encryption, refresh scope and environment endpoints). Spring Cloud Commons is a set of abstractions and common classes used in different Spring Cloud implementations (eg. Spring Cloud Netflix vs. Spring Cloud Consul).
11
+
Many of those features are covered by http://projects.spring.io/spring-boot[Spring Boot], on which Spring Cloud builds. Some more features are delivered by Spring Cloud as two libraries: Spring Cloud Context and Spring Cloud Commons.
12
+
Spring Cloud Context provides utilities and special services for the `ApplicationContext` of a Spring Cloud application (bootstrap context, encryption, refresh scope, and environment endpoints). Spring Cloud Commons is a set of abstractions and common classes used in different Spring Cloud implementations (such as Spring Cloud Netflix and Spring Cloud Consul).
9
13
10
-
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:
14
+
If you get an exception due to "Illegal key size" and you use Sun's JDK, you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/spring-cloud-commons.adoc
+31-4
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Spring Cloud builds on top of that and adds a few features that probably all com
24
24
A Spring Cloud application operates by creating a "`bootstrap`" context, which is a parent context for the main application.
25
25
It is responsible for loading configuration properties from the external sources and for decrypting properties in the local external configuration files.
26
26
The two contexts share an `Environment`, which is the source of external properties for any Spring application.
27
-
By default, bootstrap properties are added with high precedence, so they cannot be overridden by local configuration.
27
+
By default, bootstrap properties (not `bootstrap.properties` but properties that are loaded during the bootstrap phase) are added with high precedence, so they cannot be overridden by local configuration.
28
28
29
29
The bootstrap context uses a different convention for locating external configuration than the main application context.
30
30
Instead of `application.yml` (or `.properties`), you can use `bootstrap.yml`, keeping the external configuration for bootstrap and main context
@@ -87,12 +87,12 @@ context you are building), properties in that profile get loaded as well, the sa
87
87
=== Overriding the Values of Remote Properties
88
88
89
89
The property sources that are added to your application by the bootstrap context are often "`remote`" (from example, from Spring Cloud Config Server).
90
-
By default, they cannot be overridden locally, except on the command line.
90
+
By default, they cannot be overridden locally.
91
91
If you want to let your applications override the remote properties with their own System properties or config files, the remote property source has to grant it permission by setting `spring.cloud.config.allowOverride=true` (it does not work to set this locally).
92
92
Once that flag is set, two finer-grained settings control the location of the remote properties in relation to system properties and the application's local configuration:
93
93
94
94
* `spring.cloud.config.overrideNone=true`: Override from any local property source.
95
-
* `spring.cloud.config.overrideSystemProperties=false`: Only system properties and environment variables (but not the local config files) should override the remote settings.
95
+
* `spring.cloud.config.overrideSystemProperties=false`: Only system properties, command line arguments, and environment variables (but not the local config files) should override the remote settings.
96
96
97
97
=== Customizing the Bootstrap Configuration
98
98
@@ -140,6 +140,15 @@ If you create a jar with this class in it and then add a `META-INF/spring.factor
If you are going to use Spring Boot to configure log settings than
146
+
you should place this configuration in `bootstrap.[yml | properties]
147
+
if you would like it to apply to all events.
148
+
149
+
NOTE: For Spring Cloud to initialize logging configuration properly you cannot use a custom prefix. For example,
150
+
using `custom.loggin.logpath` will not be recognized by Spring Cloud when initializing the logging system.
151
+
143
152
=== Environment Changes
144
153
145
154
The application listens for an `EnvironmentChangeEvent` and reacts to the change in a couple of standard ways (additional `ApplicationListeners` can be added as `@Beans` by the user in the normal way).
@@ -160,13 +169,20 @@ For instance, a `DataSource` can have its `maxPoolSize` changed at runtime (the
160
169
Re-binding `@ConfigurationProperties` does not cover another large class of use cases, where you need more control over the refresh and where you need a change to be atomic over the whole `ApplicationContext`.
161
170
To address those concerns, we have `@RefreshScope`.
162
171
172
+
[[refresh-scope]]
163
173
=== Refresh Scope
164
174
165
175
When there is a configuration change, a Spring `@Bean` that is marked as `@RefreshScope` gets special treatment.
166
176
This feature addresses the problem of stateful beans that only get their configuration injected when they are initialized.
167
177
For instance, if a `DataSource` has open connections when the database URL is changed via the `Environment`, you probably want the holders of those connections to be able to complete what they are doing.
168
178
Then, the next time something borrows a connection from the pool, it gets one with the new URL.
169
179
180
+
Sometimes, it might even be mandatory to apply the `@RefreshScope`
181
+
annotation on some beans which can be only initialized once. If a bean
182
+
is "immutable", you will have to either annotate the bean with `@RefreshScope`
183
+
or specify the classname under the property key
184
+
`spring.cloud.refresh.extra-refreshable`.
185
+
170
186
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.
171
187
To force a bean to re-initialize on the next method call, you must invalidate its cache entry.
172
188
@@ -208,6 +224,9 @@ For a Spring Boot Actuator application, some additional management endpoints are
208
224
* `/actuator/restart` to close the `ApplicationContext` and restart it (disabled by default).
209
225
* `/actuator/pause` and `/actuator/resume` for calling the `Lifecycle` methods (`stop()` and `start()` on the `ApplicationContext`).
210
226
227
+
NOTE: If you disable the `/actuator/restart` endpoint then the `/actuator/pause` and `/actuator/resume` endpoints
228
+
will also be disabled since they are just a special case of `/actuator/restart`.
229
+
211
230
== Spring Cloud Commons: Common Abstractions
212
231
213
232
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 (for example, discovery with Eureka or Consul).
@@ -287,6 +306,14 @@ public class MyConfiguration {
287
306
288
307
Each `ServiceRegistry` implementation has its own `Registry` implementation.
289
308
309
+
* `ZookeeperRegistration` used with `ZookeeperServiceRegistry`
310
+
* `EurekaRegistration` used with `EurekaServiceRegistry`
311
+
* `ConsulRegistration` used with `ConsulServiceRegistry`
312
+
313
+
If you are using the `ServiceRegistry` interface, you are going to need to pass the
314
+
correct `Registry` implementation for the `ServiceRegistry` implementation you
315
+
are using.
316
+
290
317
291
318
==== ServiceRegistry Auto-Registration
292
319
@@ -527,7 +554,7 @@ spring:
527
554
528
555
You can also force the use of only specified network addresses by using a list of regular expressions, as shown in the following example:
0 commit comments