1. Create an empty subproject springcloud-eureka-server
2. Modify pom.xml
Increase
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
The added pom.xml is:
<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>com.xnx3.springcloud</groupId>
<artifactId>springcloud-main</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.xnx3.springcloud.eurekaserver</groupId>
<artifactId>springcloud-eureka-server</artifactId>
<!-- 以下是增加的 -->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- 以上是增加的 -->
</project>
3. Add the startup class com.xnx3.springcloud.eureka.EurekaApplication
package com.xnx3.springcloud.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
4. Add the configuration file application.properties
Add configuration file application.properties under src/main/resources/
server.port=8081
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl=defaultZone\: http\://${eureka.instance.hostname}\:${server.port}/eureka/
5. Start
Visit localhost:8081
complete!
{{o.name}}
{{m.name}}