Eureka Server
Eureka Server正常启动,并访问
server:
port: 10086
spring:
application:
name: eureka-server
security:
user:
name: eureka
password: 123456
eureka:
server:
enable-self-preservation: false # 关闭自我保护
eviction-interval-timer-in-ms: 60000 # 每隔一分钟进行一次服务列表清理
instance:
hostname: localhost
client:
register-with-eureka: false #不注册自己
fetch-registry: false
service-url:
defalutZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Eureka Client
1、添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2、application.yml
server:
port: 8085
spring:
application:
name: pay-service
eureka:
client:
service-url:
defaultZone: http://eureka:123456@localhost:10086/eureka/
3、启动类
@EnableEurekaClient
@SpringBootApplication
public class PayApplication {
public static void main(String[] args) {
SpringApplication.run(PayApplication.class,args);
}
}
直接启动,然后就自动停止
原因是缺少了web的相关依赖导致。后再在pom.xml中添加web相关依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
启动,客户端成功注册到服务端