创建注册中心:
选择Spring Initializr模板
输入坐标
选择Eureka Server
pom文件
<?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.2.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.test</groupId> <artifactId>cloud-registry</artifactId> <version>0.0.1-SNAPSHOT</version> <name>cloud-registry</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR3</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> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </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>
添加服务注解:@EnableEurekaServer
application.yml
server: port: 9010 #端口 eureka: server: enable-self-preservation: false # 设为false,关闭自我保护,会清理无效节点 eviction-interval-timer-in-ms: 30000 # 清理无效节点间隔时间(单位毫秒,默认是60*1000) instance: hostname: 127.0.0.1 preferIpAddress: true client: registerWithEureka: false #注册中心,无需注册自己 fetchRegistry: false serviceUrl: #演示调用的配置 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
原文地址:https://www.cnblogs.com/hanjun0612/p/12575810.html
时间: 2024-10-09 07:16:53