基本信息
源码名称:java 微服务 入门级实例源码(基于SpringCloud)
源码大小:0.45M
文件格式:.zip
开发语言:Java
更新时间:2020-10-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
实例中包含三个项目 eurekaServer(服务注册中心),provicer_demo(微服务提供者),caller_demo(微服务调用者),并对 服务器直接返回与调用微服务的性能 进行了简单对比,两者相差不大
下为调用方的 两个路由
下为eurekaServer
package com.example.service_caller_demo.controller;
import com.example.service_caller_demo.feignclient.SayHelloCaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller
public class Home {
@Autowired
private SayHelloCaller caller;
@RequestMapping("/sayHello")
@ResponseBody
public String sayHello(){
return caller.sayHello();
}
@RequestMapping("/hello")
@ResponseBody
public String hello(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return "我是来自caller的服务端,你好呀!" sdf.format(new Date());
}
}