前言
这篇文章是接着上一篇来的。算是专门对怎么整合的整理了一下。
上一篇地址:https://editor.csdn.net/md/?articleId=107359187
开始
ps:官方wiki里面的demo使用的版本是2.1.6的springboot,我这边使用的是2.2.7的。经过测试,发现没有影响,demo代码可以直接拿来用
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- 基础依赖 包含 mvc,aop 等jar资源 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
import com.alibaba.csp.sentinel.slots.block.SentinelRpcException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author :qilong sun
* @date :Created in 2020/7/16 9:54
* @description:
* @modified By:
* @version: V1.0$
*/
@RestController
public class IndexController {
@GetMapping("/hello")
public String apiSayHello(@RequestParam String name) {
try {
return "你好";
} catch (SentinelRpcException e) {
e.getCause().printStackTrace();
return "oops, blocked by Sentinel...";
} catch (Exception ex) {
ex.printStackTrace();
return "oops...";
}
}
@GetMapping("/test")
public String test() {
return "我是test" + System.currentTimeMillis();
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Run with: {@code -Dcsp.sentinel.api.port=8723 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=web-demo}.
*/
@SpringBootApplication(scanBasePackages = "com.demo.*")
public class SentinelDemoServer01App {
public static void main(String[] args) {
SpringApplication.run(SentinelDemoServer01App.class, args);
System.out.println("启动成功...");
}
}
# base
server.port=9526
spring.application.name=sentinel-demo-server01
# sentinel
## 指定sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=localhost:8080
OK,这就基本完成了
本文地址:https://blog.csdn.net/s1441101265/article/details/107385024
如对本文有疑问, 点击进行留言回复!!
浅析IDEA如何正确配置Gradle? GRADLE_USER_HOME 和 Gradle user home的区别
spring boot-2.1.16整合swagger-2.9.2 含yml配置文件的代码详解
有关IntelliJ IDEA中LeetCode插件配置问题
如何在Intellij中安装LeetCode刷题插件方便Java刷题
vscode检测到#include错误请更新includePath的解决方法
IDEA中使用Git拉取代码时报 Git pull failed原因及解决方法
Java8 Stream Collectors收集器使用方法解析
网友评论