spring cloud将spring boot服务注册到Eureka Server上的方法
作者:牛奋lch 时间:2023-12-08 19:42:09
开篇:
我们将前面的springboot整合H2内存数据库,实现单元测试与数据库无关性提供的Restful服务注册到spring cloud的Eureka Server上。
一、引入Eureka的Client
</dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
二、添加配置文件
# spring boot服务注册到Eureka Server上的应用名称
spring.application.name=springboot-h2
eureka.instance.prefer-ip-address=true
# Eureka Server注册服务的地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
三、开启Eureka Client支持
package com.chhliu.springboot.h2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class SpringbootH2Application {
public static void main(String[] args) {
SpringApplication.run(SpringbootH2Application.class, args);
}
}
四、启动spring boot服务并验证
通过上面几个步骤,说明我们已经将spring boot的服务注册到了Eureka Server上了!
五、可能出现的问题
如果在服务注册的过程中,发现Connection refused异常,如下:
有可能是hosts文件中没有加入如下映射关系
127.0.0.1 loaclhost
来源:http://blog.csdn.net/liuchuanhong1/article/details/54666777
标签:spring,boot,服务注册
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入理解Java设计模式之建造者模式
2022-12-06 00:57:37
![](https://img.aspxhome.com/file/2023/8/94218_0s.jpg)
Android获取设备传感器的方法
2022-10-07 10:50:16
![](https://img.aspxhome.com/file/2023/9/137219_0s.jpg)
Spring Boot利用Docker快速部署项目的完整步骤
2022-03-08 18:52:55
![](https://img.aspxhome.com/file/2023/9/84759_0s.png)
java并发编程_线程池的使用方法(详解)
2023-03-29 22:23:00
![](https://img.aspxhome.com/file/2023/1/69711_0s.png)
如何用java程序(JSch)运行远程linux主机上的shell脚本
2023-11-24 12:35:58
IntelliJ IDEA优化配置的实现
2023-01-01 03:29:55
![](https://img.aspxhome.com/file/2023/5/91055_0s.jpg)
Android Studio 生成自定义jar包的步骤详解
2023-01-31 05:02:41
![](https://img.aspxhome.com/file/2023/2/138312_0s.png)
Android开发之ProgressBar字体随着进度条的加载而滚动
2023-12-28 03:06:53
![](https://img.aspxhome.com/file/2023/4/138944_0s.gif)
Java网络编程之简易聊天室的实现
2022-05-05 22:23:45
![](https://img.aspxhome.com/file/2023/3/69113_0s.png)
C#抓取当前屏幕并保存为图片的方法
2023-09-27 08:39:43
springboot结合websocket聊天室实现私聊+群聊
2022-09-25 03:22:23
![](https://img.aspxhome.com/file/2023/9/67609_0s.jpg)
Android中退出确认框的实现代码
2022-02-23 06:40:31
![](https://img.aspxhome.com/file/2023/9/100629_0s.jpg)
关于springboot响应式编程整合webFlux的问题
2023-12-07 07:25:55
![](https://img.aspxhome.com/file/2023/0/68710_0s.png)
Spring gateway + Oauth2实现单点登录及详细配置
2022-12-19 00:16:49
![](https://img.aspxhome.com/file/2023/2/70942_0s.png)
SpringBoot实现任意位置获取HttpServletRequest对象
2023-07-07 10:26:40
Spring Boot 中密码加密的两种方法
2021-09-12 15:08:38
![](https://img.aspxhome.com/file/2023/5/78895_0s.png)
详解IDEA启动多个微服务的配置方法
2023-11-24 09:22:24
![](https://img.aspxhome.com/file/2023/0/59660_0s.png)
详解Java中LinkedHashMap
2022-05-23 16:24:45
![](https://img.aspxhome.com/file/2023/1/95031_0s.png)
Kotlin Navigation可视化开发详解
2022-10-18 10:55:56
![](https://img.aspxhome.com/file/2023/4/111714_0s.png)
Java中缀表达式转后缀表达式实现方法详解
2021-08-25 02:57:20
![](https://img.aspxhome.com/file/2023/5/104005_0s.png)