@Autowired
-private EurekaClient discoveryClient;
+private DiscoveryClient discoveryClient;
public String serviceUrl() {
InstanceInfo instance = discoveryClient.getNextServerFromEureka("STORES", false);
@@ -2600,7 +2224,7 @@ public String serviceUrl() {
- Don’t use the EurekaClient in @PostConstruct method or in a
+ Don’t use the DiscoveryClient in @PostConstruct method or in a
@Scheduled method (or anywhere where the ApplicationContext might
not be started yet). It is initialized in a SmartLifecycle (with
phase=0) so the earliest you can rely on it being available is in
@@ -2612,9 +2236,9 @@ another SmartLifecycle with higher phase.
- Alternatives to the native Netflix EurekaClient
+ Alternatives to the native Netflix DiscoveryClient
- You don’t have to use the raw Netflix EurekaClient and usually it
+ You don’t have to use the raw Netflix DiscoveryClient and usually it
is more convenient to use it behind a wrapper of some sort. Spring
Cloud has support for Feign (a REST client
builder) and also Spring RestTemplate using
@@ -2917,6 +2541,9 @@ for details on the properties available.
The same thing applies if you are using @SessionScope or @RequestScope. You will know when you need to do this because of a runtime exception that says it can’t find the scoped context.
+
+ In particular you might be interested
+
Health Indicator
@@ -3131,7 +2758,7 @@ explicitly in the @ComponentScan).
IPing ribbonPing: NoOpPing
-ServerList<Server> ribbonServerList: ConfigurationBasedServerList
+ServerList<Server> ribbonServerList: `ConfigurationBasedServerList
ServerListFilter<Server> ribbonServerListFilter: ZonePreferenceServerListFilter
@@ -3176,7 +2803,7 @@ server list will be constructed with "zone" information as provided in
the instance metadata (so on the client set
eureka.instance.metadataMap.zone), and if that is missing it can use
the domain name from the server hostname as a proxy for zone (if the
-flag approximateZoneFromHostname is set). Once the zone information is
+flag approximateZoneFromDomain is set). Once the zone information is
available it can be used in a ServerListFilter (by default it will
be used to locate a server in the same zone as the client because the
default is a ZonePreferenceServerListFilter).
@@ -3273,7 +2900,7 @@ public interface StoreClient {
List<Store> getStores();
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
- Store update(@PathVariable("storeId") Long storeId, Store store);
+ Store update(@PathParameter("storeId") Long storeId, Store store);
}
@@ -3292,239 +2919,6 @@ don’t want to use Eureka, you can simply configure a list of servers
in your external configuration (see
above for example).
-
- Overriding Feign Defaults
-
- A central concept in Spring Cloud’s Feign support is that of the named client. Each feign client is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer using the @FeignClient annotation. Spring Cloud creates a new ensemble as an
-ApplicationContext on demand for each named client using FeignClientsConfiguration. This contains (amongst other things) an feign.Decoder, a feign.Encoder, and a feign.Contract.
-
-
- Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the FeignClientsConfiguration) using @FeignClient. Example:
-
-
-
- @FeignClient(name = "stores", configuration = FooConfiguration.class)
-public interface StoreClient {
- //..
-}
-
-
-
- In this case the client is composed from the components already in FeignClientsConfiguration together with any in FooConfiguration (where the latter will override the former).
-
-
-
-
-|
- Warning
- |
-
-The FooConfiguration has to be @Configuration but take care that it is not in a @ComponentScan for the main application context, otherwise it will be used for every @FeignClient. If you use @ComponentScan (or @SpringBootApplication) you need to take steps to avoid it being included (for instance put it in a separate, non-overlapping package, or specify the packages to scan explicitly in the @ComponentScan).
- |
-
-
-
-
-
-
-|
- Note
- |
-
-The serviceId attribute is now deprecated in favor of the name attribute.
- |
-
-
-
-
-
-
-|
- Warning
- |
-
-Previously, using the url attribute, did not require the name attribute. Using name is now required.
- |
-
-
-
-
- Spring Cloud Netflix provides the following beans by default for feign (BeanType beanName: ClassName):
-
-
-
--
-
Decoder feignDecoder: ResponseEntityDecoder (which wraps a SpringDecoder)
-
--
-
Encoder feignEncoder: SpringEncoder
-
--
-
Logger feignLogger: Slf4jLogger
-
--
-
Contract feignContract: SpringMvcContract
-
-
-
-
- Spring Cloud Netflix does not provide the following beans by default for feign, but still looks up beans of these types from the application context to create the feign client:
-
-
-
- Creating a bean of one of those type and placing it in a @FeignClient configuration (such as FooConfiguration above) allows you to override each one of the beans described. Example:
-
-
-
- @Configuration
-public class FooConfiguration {
- @Bean
- public Contract feignContractg() {
- return new feign.Contract.Default();
- }
-
- @Bean
- public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
- return new BasicAuthRequestInterceptor("user", "password");
- }
-}
-
-
-
- This replaces the SpringMvcContract with feign.Contract.Default and adds a RequestInterceptor to the collection of RequestInterceptor.
-
-
- Default configurations can be specified in the @EnableFeignClients attribute defaultConfiguration in a similar manner as described above. The difference is that this configuration will apply to all feign clients.
-
-
-
- Feign Inheritance Support
-
- Feign supports boilerplate apis via single-inheritance interfaces.
-This allows grouping common operations into convenient base interfaces.
-Together with Spring MVC you can share the same contract for your
-REST endpoint and Feign client.
-
-
- UserService.java
-
- public interface UserService {
-
- @RequestMapping(method = RequestMethod.GET, value ="/users/{id}")
- User getUser(@PathVariable("id") long id);
-}
-
-
-
- UserResource.java
-
- @RestController
-public class UserResource implements UserService {
-
-}
-
-
-
- UserClient.java
-
- package project.user;
-
-@FeignClient("users")
-public interface UserClient extends UserService {
-
-}
-
-
-
-
- Feign request/response compression
-
- You may consider enabling the request or response GZIP compression for your
-Feign requests. You can do this by enabling one of the properties:
-
-
-
- feign.compression.request.enabled=true
-feign.compression.response.enabled=true
-
-
-
- Feign request compression gives you settings similar to what you may set for your web server:
-
-
-
- feign.compression.request.enabled=true
-feign.compression.request.mime-types=text/xml,application/xml,application/json
-feign.compression.request.min-request-size=2048
-
-
-
- These properties allow you to be selective about the compressed media types and minimum request threshold length.
-
-
-
- Feign logging
-
- A logger is created for each Feign client created. By default the name of the logger is the full class name of the interface used to create the Feign client. Feign logging only responds to the DEBUG level.
-
-
- application.yml
-
- logging.level.project.user.UserClient: DEBUG
-
-
-
- The Logger.Level object that you may configure per client, tells Feign how much to log. Choices are:
-
-
-
--
-
NONE, No logging (DEFAULT).
-
--
-
BASIC, Log only the request method and URL and the response status code and execution time.
-
--
-
HEADERS, Log the basic information along with request and response headers.
-
--
-
FULL, Log the headers, body, and metadata for both requests and responses.
-
-
-
-
- For example, the following would set the Logger.Level to FULL:
-
-
-
- @Configuration
-public class FooConfiguration {
- @Bean
- Logger.Level feignLoggerLevel() {
- return Logger.Level.FULL;
- }
-}
-
-
-
@@ -3548,7 +2942,7 @@ public class FooConfiguration {
- Archaius has its own set of configuration files and loading priorities. Spring applications should generally not use Archaius directly, but the need to configure the Netflix tools natively remains. Spring Cloud has a Spring Environment Bridge so Archaius can read properties from the Spring Environment. This allows Spring Boot projects to use the normal configuration toolchain, while allowing them to configure the Netflix tools, for the most part, as documented.
+ Archaius has its own set of configuration files and loading priorities. Spring applications should generally not use Archaius directly., but the need to configure the Netflix tools natively remains. Spring Cloud has a Spring Environment Bridge so Archaius can read properties from the Spring Environment. This allows Spring Boot projects to use the normal configuration toolchain, while allowing them to configure the Netflix tools, for the most part, as documented.
@@ -3628,7 +3022,7 @@ configured routes map, then it will be unignored. Example:
application.yml
zuul:
- ignoredServices: '*'
+ ignoredServices: *
routes:
users: /myusers/**
@@ -3739,7 +3133,7 @@ Set that flag to "true" to have the Ribbon client automatically retry failed req
the Ribbon client configuration).
- The X-Forwarded-Host header is added to the forwarded requests by
+ The X-Forwarded-Host header added to the forwarded requests by
default. To turn it off set zuul.addProxyHeaders = false. The
prefix path is stripped by default, and the request to the backend
picks up a header "X-Forwarded-Prefix" ("/myusers" in the examples
@@ -3750,80 +3144,6 @@ above).
server if you set a default route ("/"), for example zuul.route.home:
/ would route all traffic (i.e. "/**") to the "home" service.
-
- If more fine-grained ignoring is needed, you can specify specific patterns to ignore.
-These patterns are being evaluated at the start of the route location process, which
-means prefixes should be included in the pattern to warrant a match. Ignored patterns
-span all services and supersede any other route specification.
-
-
- application.yml
-
- zuul:
- ignoredPatterns: /**/admin/**
- routes:
- users: /myusers/**
-
-
-
- This means that all calls such as "/myusers/101" will be forwarded to "/101" on the "users" service.
-But calls including "/admin/" will not resolve.
-
-
-
- Strangulation Patterns and Local Forwards
-
- A common pattern when migrating an existing application or API is to
-"strangle" old endpoints, slowly replacing them with different
-implementations. The Zuul proxy is a useful tool for this because you
-can use it to handle all traffic from clients of the old endpoints,
-but redirect some of the requests to new ones.
-
-
- Example configuration:
-
-
- application.yml
-
- zuul:
- routes:
- first:
- path: /first/**
- url: http://first.example.com
- second:
- path: /second/**
- url: forward:/second
- third:
- path: /third/**
- url: forward:/3rd
- legacy:
- path: /**
- url: http://legacy.example.com
-
-
-
- In this example we are strangling the "legacy" app which is mapped to
-all requests that do not match one of the other patterns. Paths in
-/first/ have been extracted into a new service with an external
-URL. And paths in /second/ are forwared so they can be handled
-locally, e.g. with a normal Spring @RequestMapping. Paths in
-/third/** are also forwarded, but with a different prefix
-(i.e. /third/foo is forwarded to /3rd/foo).
-
-
-
-
-|
- Note
- |
-
-The ignored pattterns aren’t completely ignored, they just
-aren’t handled by the proxy (so they are also effectively forwarded
-locally).
- |
-
-
-
Uploading Files through Zuul
@@ -4116,8 +3436,8 @@ Spring CLI v1.2.3.RELEASE
- $ gvm install springboot 1.3.0.M5
-$ gvm use springboot 1.3.0.M5
+ $ gvm install springboot 1.2.3.RELEASE
+$ gvm use springboot 1.2.3.RELEASE
@@ -4126,7 +3446,7 @@ $ gvm use springboot 1.3.0.M5
$ mvn install
-$ spring install org.springframework.cloud:spring-cloud-cli:1.1.0.BUILD-SNAPSHOT
+$ spring install org.springframework.cloud:spring-cloud-cli:1.0.2.RELEASE
@@ -4226,7 +3546,7 @@ AQAjPgt3eFZQXwt8tsHAVv/QHiY5sI2dRcR+...
|