一、maven依赖如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<!-- 管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- SpringBoot整合Web组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringBoot整合eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
二、启动类添加注解:@EnableEurekaClient
如下
@SpringBootApplication
//将当前服务注册到eureka上
@EnableEurekaClient
public class MemberApp {
public static void main(String[] args) {
SpringApplication.run(MemberApp.class, args);
}
}
三、application.yml文件配置如下:
###eureka 服务端口号
server:
port: 8000
###服务注册名称
###服务名称(服务注册到eureka名称)
spring:
application:
name: app-member
eureka:
instance:
hostname: 127.0.0.1
###服务注册到eureka地址
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8100/eureka/
###注册到eureka上
register-with-eureka: true
###需要检索服务
fetch-registry: true
eureka.client.serviceUrl.defaultZone为eureka注册中心的defaultZone
spring.application.name为提供的服务的名称
四、部署完毕
如图即为发布成功