会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题
会帮你学得更全面
截止目前,同学们一共提了 115489个问题,问题会在24小时内得到回答
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Spring Cloud Alibaba 3楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Spring Cloud Alibaba 4楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Nacos 6楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Seata 7楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Sentinel 8楼

老师,我这边的java异常回退可以正常进行;限流异常的时候,进不去我配置的拦截。浏览器中显示的是“Blocked by Sentinel (flow limiting)”,没有进入到我配置的拦截中。

代码如下:


启动类:

com.zhengcom.alibaba.csp.sentinel.annotation.com.alibaba.csp.sentinel.slots.block.BlockExceptioncom.zheng.fall.RpcBlockHandlerConfigorg.springframework.beans.factory.annotation.org.springframework.boot.SpringApplicationorg.springframework.boot.autoconfigure.org.springframework.cloud.client.loadbalancer.org.springframework.context.annotation.org.springframework.http.HttpStatusorg.springframework.http.ResponseEntityorg.springframework.web.bind.annotation.org.springframework.web.bind.annotation.org.springframework.web.bind.annotation.org.springframework.web.client.RestTemplateSentinelConsumerApplication9090 {

    (String[] args) {
        SpringApplication.(SentinelConsumerApplication9090.args)}

    RestTemplate (){
        RestTemplate()}RestTemplate (= )
    (
            = = RpcBlockHandlerConfig.= = RpcBlockHandlerConfig.= )
    ResponseEntity<String> ((= )String type){
        (.equals(type)) {
            RuntimeException()}

        System..println()ResponseEntity<String> forEntity = .getForEntity(String.)(forEntity.getStatusCode() == HttpStatus.) {
            ResponseEntity.(+ forEntity.getBody())} RuntimeException()}

}



配置类:

com.zheng.fallcom.alibaba.csp.sentinel.slots.block.BlockExceptionorg.springframework.http.ResponseEntityRpcBlockHandlerConfig {

    ResponseEntity<String> (String typeThrowable t){
        System..println(+t.getMessage())ResponseEntity.()}

    ResponseEntity<String> (String typeBlockException t){
        System..println(+t)ResponseEntity.()}
}



页面效果:

image.png



没用进入到我配置的“handler” 方法中去。这是为什么啊




JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Sentinel 9楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Seata 10楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/Seata 11楼
JAVA 全系列/第二十一阶段:Spring Cloud Alibaba技术栈/RocketMQ 13楼

百战程序员微信公众号

百战程序员微信小程序

©2014-2023 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2020212637