Eureka服务端配置
- 创建微服务Project,新建Module,在Module的pom.xml中配置如下依赖。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- 在服务端加入
@EnableEurekaServer注解。
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}
- 在
application.yml配置文件中加入如下配置。
server:
port: 8761
spring:
application:
name: eureka-service
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka
Eureka客户端注册配置
- 在
application.yml配置文件中加入如下配置。
spring:
application:
name: user-service
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka