一 Eureka-server 注册中心
1.pom配置
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-autoconfigure
2.application.yml
server: port: 10086 spring: application: name: eurekaserver #eureka的名称 eureka: client: service-url: #eureka的通信地址 defaultZone: http://127.0.0.1:10086/eureka
3.SpringbootApplication启动项
@EnableEurekaServer
二、eureka-client 客户端配置 1.设置pom
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
2. 设置application.yml
#eureka-cli eureka: client: service-url: #eureka的通信地址 defaultZone: http://127.0.0.1:10086/eurekaspring: application: name: orderservice #eureka的user服务名称
如果本地需要多个配置
右键复制一个新的running 进行修改,名字修改和截图内红框参数需要添加
运行后,可以在
http://127.0.0.1:10086/ 注册中心看到运行状况
服务拉取
1.修改代码url访问路径,用服务名替代ip,端口:
Spring url = "http://USERSERVER/user/" + order.getUser();
2.在启动项Application中的RestTemplate添加负载均衡注解。
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
Eureka常用配置情况有异常或者有问题的可以给我留言。互相学习~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)