Server
selection dependency
Start class
@SpringBootApplication
@EnableEurekaServer
public class CloudApplication {
public static void main(String[] args) {
SpringApplication.run(CloudApplication.class, args);
}
}
Configuration file
server:
port: 7000
spring:
application:
name: eureka-server-7000 #表示应用名称,在注册中心中显示的服务注册名称
eureka:
instance: #定义Eureka实例
hostname: localhost # 定义 Eureka 实例所在的主机名称
client: #eureka客户端配置
fetch-registry: false # 表示客户端是否从 Eureka Server 获取实例注册信息,false表示自己就是注册中心。我的职责就是维护服务实例,并不需要去检索服务
register-with-eureka: false #表示此实例是否注册到 Eureka Server 以供其他实例发现,false表示自己不需要向注册中心注册自己
service-url:
defaultZone: http://${
eureka.instance.hostname}:${
server.port}/eureka/ #defaultZone必须驼峰,表示客户端需要注册的 Eureka Server 的地址
Client
depends on selecting eureka and web
startup class plus @EnableEurekaClient
configuration file yml
spring:
application:
name: eureka-client-8001
eureka:
client:
service-url:
defaultZone: http://localhost:7000/eureka/ #defaultZone必须驼峰
server:
port: 8001
Eureka server has an interface, start the project, open the browser to visit:
http://localhost:7000, the interface is as follows