欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-26 10:31:30
...

创建消费者
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");

}
相关标签: springcloud