eureka中注册服务以及订单微服务的配置项一致
以下为注册服务的配置
订单微服务的配置只需将properties中的端口号以及服务名称进行修改即可
1.添加核心依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
2.配置properties
server.port=8001
#微服务名称,保持唯一
spring.application.name=cloud-payment-service
#表示是否将自己注册进eurekaServer,默认为true
eureka.client.register-with-eureka=true
#表示是否从eurekaServer抓取已有的注册信息,默认为true。单点无所谓,集群必须设置为true才能配置ribbon使用负载均衡
eureka.client.fetch-registry=true
#注册中心url
eureka.client.service-url.defaultZone=http://localhost:7001/eureka
3.启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
//表示该模块为要进行服务的注册
@EnableEurekaClient
public class Payment8001 {
public static void main(String[] args) {
SpringApplication.run(Payment8001.class,args);
}
}