Spring Cloud Eureka 服务治理学习2 注册服务提供者
Posted 编程圈子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Cloud Eureka 服务治理学习2 注册服务提供者相关的知识,希望对你有一定的参考价值。
一、操作
1. pom
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2. 入口类
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author Cade on 2021-5-31
*/
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@EnableAdminServer
@SpringBootApplication
@EnableDiscoveryClient
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication .class, args);
}
}
3. 配置文件
eureka:
client:
registryFetchIntervalSeconds: 5
service-url:
defaultZone: http://eureka服务端ip:eureka端口号/eureka/
instance:
prefer-ip-address: true
ip-address: 服务提供者ip
non-secure-port: 服务提供者端口
instance-id: 实例名称
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
二、启动效果
以上是关于Spring Cloud Eureka 服务治理学习2 注册服务提供者的主要内容,如果未能解决你的问题,请参考以下文章
基于Spring Cloud的微服务构建学习-3 Spring Cloud Eureka配置详解