2.1 pom.xml
在有的教程中,会引入 spring-boot-starter-web,这个依赖其实不用,因为 spring-cloud-starter-netflix-eureka-server的依赖已经包含了它,在pom依赖进去,就可以了
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency>
2.2 application.yml
- server:
- port: 8500
- eureka:
- client:
- #是否将自己注册到Eureka Server,默认为true,由于当前就是server,故而设置成false,表明该服务不会向eureka注册自己的信息
- register-with-eureka: false
- #是否从eureka server获取注册信息,由于单节点,不需要同步其他节点数据,用false
- fetch-registry: false
- #设置服务注册中心的URL,用于client和server端交流
- service-url:
- defaultZone: http://localhost:8080/eureka/
2.3 服务端启动类
启动类上添加此注解标识该服务为配置中心@EnableEurekaServer
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
- @EnableEurekaServer
- @SpringBootApplication
- public class EurekaServerApplication {
- public static void main(String[] args) {
- SpringApplication.run(EurekaServerApplication.class, args);
- }
- }
2.4 启动
我们启动 EurekaDemoApplication,然后在浏览器中输入地址 http://localhost:8500/,就可以启动我们的 Eureka 了,我们来看下效果,出现了这个画面,就说明我们已经成功启动~,只是此时我们的服务中是还没有客户端进行注册