注册中心
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
- 启用Eureka Server
在启动类或者配置类上添加
@EnableEurekaServer
/**
* 服务注册中心
*/
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
private static CountDownLatch latch = new CountDownLatch(1);
public static void main(String[] args) throws InterruptedException {
// registerShutdownHook : 平滑关闭 SpringBoot
SpringApplication.run(EurekaServerApplication.class, args).registerShutdownHook();
latch.await();
}
}
spring:
application:
name: eureka-server
eureka:
instance:
hostname: eureka-server
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://localhost:8761/eureka
server:
enable-self-preservation: false
- 验证
启动项目后访问
http://localhost:8761
服务注册