【Spring Cloud】服务注册与发现Eureka
一、环境准备
-
JDK Version: 1.8
-
Maven Version: 3.6.2
-
IDEA工具
安装以上东东,并配置环境变量
二、创建服务注册发现中心
新建spring boot项目
spring boot version: 2.3.4.RELEASE
创建步骤略
spring cloud version
Hoxton.SR8
添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
服务配置
-
application.yml
server: port: 8000 //服务接口 spring: application: name: eureka-server //服务名称 eureka: instance: hostname: localhost client: //是否将自身也注册为一个服务 register-with-eureka: false fetch-registry: false
-
添加注解@EnableEurekaServer
@EnableEurekaServer @SpringBootApplication public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
三、运行结果
- 输入http://localhost:8000