博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud服务提供者
阅读量:4329 次
发布时间:2019-06-06

本文共 3195 字,大约阅读时间需要 10 分钟。

服务提供者就是提供一个服务暴露出来给别人调用,在springcloud中需要注册服务到服务中心

搭建服务提供者项目(ProduceDemo)

1、创建pom.xml

4.0.0
com.cppdy
ProduceDemo
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
UTF-8
UTF-8
1.8
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
Dalston.RC1
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false

2、创建application.yml配置文件

eureka:  client:    service-url:      defaultZone: http://127.0.0.1:9000/eureka/      #注册到哪个服务中心上server:  port: 9001  #当前服务的端口spring:  application:    name: cppdy-hello    #服务的名字

3、创建测试类(HelloController)

package com.cppdy.controller;import org.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController {    @Value("${server.port}")    private String port;        @RequestMapping("hello")    public String hello(String name) {        return "Hello"+name+",From port:"+port;    }}

4、创建启动类(ProduceApp) 

package com.cppdy;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClientpublic class ProduceApp {    public static void main(String[] args) {        SpringApplication.run(ProduceApp.class, args);    }}

5、先启动EurekaDemo(注册中心项目),再启动ProduceDemo(服务提供者项目),访问http://localhost:9000/,看到服务的名字表示注册成功

转载于:https://www.cnblogs.com/jiefu/p/10055166.html

你可能感兴趣的文章
[BZOJ 4010] 菜肴制作
查看>>
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>
VsVim - Shortcut Key (快捷键)
查看>>
C++练习 | 模板与泛式编程练习(1)
查看>>
HDU5447 Good Numbers
查看>>
08.CXF发布WebService(Java项目)
查看>>
java-集合框架
查看>>
RTMP
查看>>
求一个数的整数次方
查看>>
点云PCL中小细节
查看>>
铁路信号基础
查看>>
RobotFramework自动化2-自定义关键字
查看>>
[置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
查看>>
BABOK - 需求分析(Requirements Analysis)概述
查看>>
第43条:掌握GCD及操作队列的使用时机
查看>>
Windows autoKeras的下载与安装连接
查看>>
CMU Bomblab 答案
查看>>
微信支付之异步通知签名错误
查看>>
2016 - 1 -17 GCD学习总结
查看>>