pom.xml: 留意spring-boot和spring-cloud的版本号需要一致,如Hoxton SR5后的spring-boot版本需为2.3.x,如果版本不一致,会发生很多意想不到的问题。如找不到@EnableEurekaServer注解所在包,尽管对应的包已经导入到maven中。
4.0.0 com.xxx eureka-study0.0.1-SNAPSHOT eureka-server Demo project for Spring Boot 1.8 UTF-8 UTF-8 2.3.1.RELEASE Hoxton.SR12 org.springframework.boot spring-boot-starterorg.springframework.boot spring-boot-starter-testtest org.junit.vintage junit-vintage-engineorg.springframework.cloud spring-cloud-starter-netflix-eureka-serverorg.springframework.boot spring-boot-dependencies${spring-boot.version} pom import org.springframework.cloud spring-cloud-dependencies${spring-cloud.version} pom import
EurekaServerApplication.java:
package com.xxx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
application.properties:
# spring.application.name=eureka-server server.port=1001 eureka.instance.hostname=localhost eureka.client.register-with-eureka=false eureka.client.fetch-registry=false
启动spring-boot项目,访问1001端口即可。



