1.导入 依赖
建议直接使用idea导入依赖 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cz</groupId>
<artifactId>eurekaCenter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eurekaCenter</name>
<description>eurekaCenter</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.编写yml文件
server:
port: 9001
eureka:
instance:
ip-address: true # 以ip形式进行注册
lease-expiration-duration-in-seconds: 90 # 至少90s发送一次心跳给我
lease-renewal-interval-in-seconds: 30 # 设置30s就发送一次心跳
client:
register-with-eureka: false #是否向服务注册中心注册自己 默认true
fetch-registry: false # 是否向服务注册中心拉去注册表信息 默认true
service-url:
defaultZone: http:
spring:
application:
name: eurekaCenter
3.启动类上加注解支持@EnableEurekaServer
package com.cz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaCenterApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaCenterApplication.class, args);
}
}
4.启动项目
访问localhost:9001即可
|