spring cloud-将spring boot服务注册到Eureka Server上

来源:互联网 发布:通过网络被骗的案例 编辑:程序博客网 时间:2024/06/07 01:39

开篇:

我们将前面的

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-h2eureka.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@EnableEurekaClientpublic 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

0 0
原创粉丝点击