开发者社区 > 云原生 > 正文

我的应用程序似乎无法使用Sentinel来帮助我配置Controller中的URL资源。

我的代码看起来是这样的,我将首先在接口中定义它,然后实现它。

@Api(value = "sms", description = "the sms API") @RequestMapping(value = "/api/v1/message") public interface SmsApi {

@ApiOperation(value = "XXXXX", nickname = "smsAsyncSendPost", notes = "XXXXX", response = Integer.class, tags={ "sms", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "OK", response = Integer.class) })
@RequestMapping(value = "/sms/async-send",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.POST)
ResponseEntity<Integer> smsAsyncSendPost(@ApiParam(value = "XXXX" ,required=true )  @Valid @RequestBody Sms body);

}

@RestController public class SmsApiImpl implements SmsApi {

@Autowired
private SmsService smsService;

@Override
public ResponseEntity<Integer> smsAsyncSendPost(@Valid Sms sms) {
    try {
        this.smsService.smsAsyncSendPost(sms);
        return ResponseEntity.ok(1);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(0);
}

}

我写了一个最简单的请求,发现Sentinel可以做URL资源。

@RestController public class SentinelController {

@GetMapping("/hello")
public String hello() {
    return "Hello Sentinel";
}

}

提问151.png

我使用的版本和配置如下

com.alibaba.cloud spring-cloud-starter-alibaba-sentinel 2.2.0.RELEASE

spring.cloud.sentinel.transport.port=8719 spring.cloud.sentinel.transport.dashboard=localhost:8080 management.endpoints.web.exposure.include=*

原提问者GitHub用户bbqtk

展开
收起
云上静思 2023-05-19 16:33:53 109 0
1 条回答
写回答
取消 提交回答
  • 将其添加到application.properties中:

    spring.cloud.sentinel.filter.url-patterns=/**

    这是由于旧版本的春季云启动器alibaba sentinel中的默认模式/*造成的。 它在最新版本中进行了改进,不需要添加此配置。

    原回答者GitHub用户cdfive

    2023-05-19 22:43:43
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
阿里云容器 AHAS Sentinel 网关流控揭秘 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-使用Sentinel进行微服务流量控制 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载