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 http://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.1.6.RELEASE</version>
<relativePath/> <!-- 不指定路径则从maven库中查找父级 -->
</parent>
<groupId>com.aaron</groupId>
<artifactId>springcloud</artifactId>
<version>1.0-SNAPSHOT</version>
<name>springcloud</name>
<description>Demo project for Spring Boot</description>
<!-- 指定统一版本 -->
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</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>
配置文件application.yml:
# 指定该服务端口
server:
port: 8016
eureka:
instance:
#指定IP地址
hostname: 127.0.0.1
client:
#是否向服务注册中心注册自己
register-with-eureka: false
fetch-registry: false
#注册中心web路由地址
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
SpringBoot启动项:
package com.aaron.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class SpringCloudApplication {
public static void main(String[] args){
SpringApplication.run(SpringCloudApplication.class,args);
}
}
效果:
注意事项:多版本SpringBoot Jar包可能导致jar包import失败或失效。可尝试右击项目->Maven->reimport
或者删除本地maven仓库中相关jar包重新reimport