SpringCloud学习二之服务注册和服务发现Eureka入门服务消费者的搭建

创建消费者
1.pom文件中添加eureka的岂步依赖
2.配置文件添加eureka.client的相关配置
server.port=8080
#应用的名称
spring.application.name=api-geteway
eureka.client.service-url.defaultZone=http://127.0.0.1:8666/eureka/
3.启动类注解@EnableDiscoveryClient
@SpringBootApplication
@EnableDiscoveryClient
@Controller
public class ApiGetawayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGetawayApplication.class, args);
}

@Autowired
private DiscoveryClient discoveryClient;


@RequestMapping("index1")
@ResponseBody
public List<ServiceInstance> getRegister() {
    return discoveryClient.getInstances("user");

}

猜你喜欢

转载自blog.csdn.net/weixin_39361197/article/details/83855756