注册中心是微服务体系的核心组件之一,负责服务的自动注册与发现,下面详细介绍下Eureka服务端搭建步骤
新建maven项目,pom文件如下
<groupId>com.gitee.xushiling</groupId>
<artifactId>spring-cloud-eureka</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<!-- eureka服务端 -->
<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.java 启动文件
/**
* @author :xushiling
* @date :2020/11/26 14:34
*/
@EnableEurekaServer #启用Eureka服务端功能
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
新建application.yml配置文件
spring:
application:
name: spring-cloud-eureka
server:
port: 3000
eureka:
instance:
hostname: spring-cloud-eureka
appname: eureka注册中心
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:3000/eureka
server:
enableSelfPreservation: false
evictionIntervalTimerInMs: 4000
启动此工程,打开http://localhost:3000/
即可看到eureka控制台
网友评论