摘要:本文主要向大家介绍了JAVA语言的spring-cloud入门之eureka-client,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
本文主要向大家介绍了JAVA语言的spring-cloud入门之eureka-client,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
上一节我们搭建起了服务注册中心,为各个服务提供者和消费者提供一个桥梁,这一节我们搭建一个服务提供者,注册到注册中心
开源地址:https://github.com/bigbeef
新建eureka-client模块
代码结构如下:
代码编写
cppba-spring-cloud-eureka-client > pom.xml
<project xmlns="//maven.apache.org/POM/4.0.0" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="//maven.apache.org/POM/4.0.0 //maven.apache.org/xsd/maven-4.0.0.xsd">
复制代码
SpringCloudEurekaClientApplication.java
package com.cppba;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableEurekaClient
@RestController
public class SpringCloudEurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudEurekaClientApplication.class, args);
}
@Value("${server.port}")
private String port;
@RequestMapping("/hi")
public String sayHi(@RequestParam String name) {
return "hi " + name + ",i am from port:" + port;
}
}
复制代码
application.properties
server.port=8764
eureka.client.serviceUrl.defaultZone=//localhost:8761/eureka/
spring.application.name=service-say
复制代码
到此项目搭建完成
启动项目
启动eureka-client之前,我们先启动上一节搭建的eureka-server,两个服务都启动好以后,我们访问注册中心,可以看到:
说明我们服务注册成功!访问一下//127.0.0.1:8764/hi?name=hornet
到此,eureka-client(服务发现)项目搭建成功。
参考项目:https://github.com/bigbeef/cppba-spring-cloud
github地址:https://github.com/bigbeef
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注编程语言JAVA频道!
擅长针对企业软件开发的产品设计及开发的细节与流程设计课程内容。座右铭:大道至简!
已有23人表明态度,87%喜欢该老师!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号