一、定义controller
package cn.edu.tju.controller;import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HotParamController {@RequestMapping("/getHotParam/{id}")@SentinelResource(value = "getHotParam", blockHandler = "myBlockHandler")public String getHotParam(@PathVariable String id){return "get: " + id;}public String myBlockHandler(@PathVariable String id, BlockException ex){return "get: 热点数据";}
}
二、配置热点参数限制规则
然后编辑规则: