首先添加依赖包:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
在app里添加服务发现注解:
@SpringBootApplication
@EnableEurekaServer //服务发现
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
然后写配置文件application.yml:
server:
port: 8761 #eureka默认端口
eureka:
client:
register-with-eureka: false #不把他当成eureka client只当成eureka server
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka #把eureka部到哪个url下
启动项目,打开http://localhost:8761/eureka网页访问观看效果如下: