目录
本文的主要工作是介绍如何搭建一个Eureka服务
1.首先引入依赖
pom文件中加入依赖
bash
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.main中配置注解
SpringBoot启动的主类中添加@EnableEurekaServer
java
package cn.itcast;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer //关键注解
@SpringBootApplication
public class EurekaApplication {//在SpringBoot启动的主类中添加@EnableEurekaServer
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}
3.src/main/resources/application.yml配置文件
src/main/resources/application.yml配置项目信息
yml
server:
port: 10086 #配置项目端口
spring:
application:
name: eurekaserver #euraka的服务名称,把Eureka自己也加入到注册名单中
eureka:
client:
service-url:#eureka的地址信息
defaultZone: http://localhost:10086/eureka