SpringCloudAlibaba-15-sentinel规则持久化-nacos

1.引入依赖

1
2
3
4
5
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.7.0</version>
</dependency>

2.application.yml添加配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
server:
port: 18080
spring:
application:
name: sentinel-core-example
cloud:
sentinel:
transport:
dashboard: 127.0.0.1:8080
datasource:
ds1:
file:
file: classpath:flowrule.json
data-type: json
rule-type: flow
ds2:
nacos:
server-addr: 127.0.0.0.1:8848
dataId: sentinel-core-example
groupId: DEFAULT_GROUP
data-type: json
rule-type: flow
```
#### 3.启动nacos
重启nacos,然后创建sentinel-core-example配置文件
![](https://raw.githubusercontent.com/startshineye/img/master/2020/02/33.png)
HellController添加:

@GetMapping(“/resource1”)
@SentinelResource(value = “hello2”, blockHandler = “exHandler”, blockHandlerClass = {ExceptionUtil.class})
public String resource1() {
return “hello resource1”;
}
```

毕业于<br>相信技术可以改变人与人之间的生活<br>码农一枚