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">
<parent>
<artifactId>SpringCloudFoundation</artifactId>
<groupId>com.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eurekaclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
</project>
bootstrap.properties 配置
server.port=8010
# 当前服务注册在 Eureka Server 上的名称
spring.application.name=provider
# 注册中心的访问地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
# 是否将当前服务的 IP 注册到 Eureka Server
eureka.instance.prefer-ip-address=true
启动类跟 Spring Boot 的一样
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
测试
在启动 EurekaServerApplication 后启动 ProviderApplicaiton,进入 http://localhost:8761 会显示 PROVIDER 则成功。