@EnableDiscoveryClient和@EnableEurekaClient的区别?马 克-to-win@马克java社区:在前面的服务提供者的例子中我们是用@EnableEurekaClient,其实二者的功能是一样的。但是如果选 用的是eureka服务器,那么就推荐@EnableEurekaClient,如果是其他的注册中心,那么推荐使用 @EnableDiscoveryClient。
马克-to-win@马克java社区:下面的RestTemplate本身不具备调用分布式服务的能力,但被@LoadBalanced修饰后就具有访问分布式服务的能力了(本helloworld例子不做探讨)
package com;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate () {
return new RestTemplate ();
@EnableDiscoveryClient和@EnableEurekaClient的区别?
猜你喜欢
转载自blog.csdn.net/mark_to_win/article/details/88741265
今日推荐
周排行