首先,Spring-Cloud目前是行业的潮流,貌似不会就落后了,笔者为了不脱离大部队只能深入学习一下了。

其次、跳槽到一家公司,给公司推荐了Jeecg-Boot的开发平台,那么为了后面扩展为cloud也需要学习了。

废话不多说,跟着Jeecg团队出品的视频学习,发现没有给源代码,搞开发这一行眼过千遍不如手过一遍,还是跟着视频敲一遍,为了方便大家把源码贴在下面

Jeecg-CloudB站视频地址(V2.2.0):https://www.bilibili.com/video/BV1pV411r7xW

nacos下载地址(V1.2.1):https://pan.baidu.com/s/1XtAguW4JNrwuGF-U3SNSeQ     提取码:z7d9

————————————————————————————————————————————————————————————————————————

首先新建一个Maven项目,jeecg-cloud,父项目的pom.xml文件如下面代码所示:

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>jeecg-cloud</groupId>
<artifactId>jeecg-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>jeecg-provider</module>
<module>jeecg-config</module>
<module>jeecg-gateway</module>
<module>jeecg-feign</module>
</modules> <packaging>pom</packaging> <dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency> <dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency> </dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins> <resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build> </project>

之后新建一个jeecg-provider模块(具体步骤参见视频,我这里只是把他们的PPT上面的依赖、配置、代码写下来):

pom.xml(jeecg-provider)文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jeecg-cloud</artifactId>
<groupId>jeecg-cloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>jeecg-provider</artifactId> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> <!--服务降级、熔断-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
</dependencies>
</project>

application.yml:

server:
port: 8082
spring:
application:
name: jeecg-provider
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848

ProviderApplication.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /**
* @author zx
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
public class ProviderApplication { public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class,args);
}
}

TestController.java

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; /**
* @author zx
*/
@RestController
@RequestMapping("/test")
public class TestController { @Value("${server.port}")
private String serverPort; @RequestMapping("/one")
public String one(){
return "my port is: "+serverPort;
} @RequestMapping("/showName/{name}")
public String showName(@PathVariable("name") String name){ try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "your name is : " + name;
} @HystrixCommand(fallbackMethod = "hystrixDefault",commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")})
@RequestMapping("/hystrixTest/{name}")
public String hystrixTest(@PathVariable("name") String name) {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "我是正常的返回" + name;
} private String hystrixDefault(String name){
return "程序超市 " + name;
} @HystrixCommand(fallbackMethod = "netFallback",commandProperties = {
@HystrixProperty(name = "circuitBreaker.enabled",value = "true"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "10"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "5000"),})
@GetMapping("/net/{age}")
public String net(@PathVariable("age") int age){
if (age < 18){
throw new RuntimeException();
}
return "正在上网,年龄 " +age;
} public String netFallback(@PathVariable("age") int age){
return "未成年,不允许进入网吧,年龄 " +age;
}
}

其他模块请看下一篇,就不要搞得篇幅太长了。

Jeecg-Cloud学习之路(一)的更多相关文章

  1. .net core+Spring Cloud学习之路 二

    前言: 原本计划这次写一下搭建eureka群集.但是发现上次写的只是服务的注册,忘了写服务的发现,所以这次先把服务发现补上去. 我们基于上篇文章,再新建两个.net core web api项目,分别 ...

  2. .net core+Spring Cloud学习之路 一

    文章开头唠叨两句. 2019年了,而自己参加工作也两年有余了,用一个词来概括这两年多的生活,就是:“碌碌无为”. 也不能说一点收获都没有,但是很少.2019来了,我立志要打破现状,改变自己,突破自我. ...

  3. jQuery学习之路(1)-选择器

    ▓▓▓▓▓▓ 大致介绍 终于开始了我的jQuery学习之路!感觉不能再拖了,要边学习原生JavaScript边学习jQuery jQuery是什么? jQuery是一个快速.简洁的JavaScript ...

  4. Android开发学习之路-RecyclerView滑动删除和拖动排序

    Android开发学习之路-RecyclerView使用初探 Android开发学习之路-RecyclerView的Item自定义动画及DefaultItemAnimator源码分析 Android开 ...

  5. RPC远程过程调用学习之路(一):用最原始代码还原PRC框架

    RPC: Remote Procedure Call 远程过程调用,即业务的具体实现不是在自己系统中,需要从其他系统中进行调用实现,所以在系统间进行数据交互时经常使用. rpc的实现方式有很多,可以通 ...

  6. webService学习之路(三):springMVC集成CXF后调用已知的wsdl接口

    webService学习之路一:讲解了通过传统方式怎么发布及调用webservice webService学习之路二:讲解了SpringMVC和CXF的集成及快速发布webservice 本篇文章将讲 ...

  7. [精品书单] C#/.NET 学习之路——从入门到放弃

    C#/.NET 学习之路--从入门到放弃 此系列只包含 C#/CLR 学习,不包含应用框架(ASP.NET , WPF , WCF 等)及架构设计学习书籍和资料. C# 入门 <C# 本质论&g ...

  8. Redis——学习之路四(初识主从配置)

    首先我们配置一台master服务器,两台slave服务器.master服务器配置就是默认配置 端口为6379,添加就一个密码CeshiPassword,然后启动master服务器. 两台slave服务 ...

  9. Redis——学习之路三(初识redis config配置)

    我们先看看config 默认情况下系统是怎么配置的.在命令行中输入 config get *(如图) 默认情况下有61配置信息,每一个命令占两行,第一行为配置名称信息,第二行为配置的具体信息.     ...

  10. Redis——学习之路二(初识redis服务器命令)

    上一章我们已经知道了如果启动redis服务器,现在我们来学习一下,以及如何用客户端连接服务器.接下来我们来学习一下查看操作服务器的命令. 服务器命令: 1.info——当前redis服务器信息   s ...

随机推荐

  1. luogu P3920 [WC2014]紫荆花之恋

    LINK:紫荆花之恋 每次动态加入一个节点 统计 有多少个节点和当前节点的距离小于他们的权值和. 显然我们不能n^2暴力. 考虑一个简化版的问题 树已经给出 每次求某个节点和其他节点的贡献. 不难想到 ...

  2. 三类安装VMTools失败的解决方法(Windows、Linux、MacOs)

    前言 写这篇笔记的原因,是前几天在虚拟机 Vmware 中重新安装了几个操作系统,突然发现 VMTools 这个工具成了一个特殊的问题,以前还没有发现,因为通常它就给你自动安装了.但是大多数时候也是需 ...

  3. [转] 9种设计模式在Spring中的运用

    作者:iCoding91地址:https://blog.csdn.net/caoxiaohong1005 转发的公众号地址,有其他设计模式介绍:https://mp.weixin.qq.com/s/Z ...

  4. 初识分布式:MIT 6.284系列(一)

    前言 本系列是源于「码农翻身」所属知识星球发起的读书活动,由大佬 @我的UDP不丢包 推荐而来,这次的读书活动有一些另类,我们抛弃了传统的书籍,开始攻略最高学府的研究生顶级课程 <6.824&g ...

  5. Jmeter无法监听服务器4444端口

    阿里云服务器开放了4444端口 jmeter还是无法监听: 解决方法: 阿里云安全组添加端口5555 服务器中启动监听插件使用5555端口,使用命令:java -jar ./CMDRunner.jar ...

  6. Java助教工作总结

    很荣幸在步入在研究生之际,有机会能协助代老师完成面向对象程序设计(java)课程的教学工作.这也是我人生中第一次接触助教工作,好多东西不太清楚,也没经验,有什么做的不好的,还望老师同学及时指出. 上周 ...

  7. CI4框架应用二 - 项目目录

    我们之前搭建好了CI4的开发环境,下面我们来看一下CI4的目录结构. Administrator@PC- MINGW64 /c/wamp64/www/ci4 $ ls -l total drwxr-x ...

  8. Python人脸识别 + 手机推送,老板来了你就会收到短信提示

  9. java Hibernate 用法

    Hibernate 用法总结: import java.io.Serializable; import java.sql.SQLException; import java.util.Collecti ...

  10. 2020-07-04:tcp三次握手干了啥?time_wait什么时候出现?

    福哥答案2020-07-04:三次握手如下:1.SYN j2.ACK j+1,SYN k3.ACK k+1 time_wait出现在断开连接第四次挥手的时候出现.TIME_WAIT状态存在有两个原因. ...