alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.38k stars 8.02k forks source link

It seems that my application cannot use Sentinel to help me configure the URL resources in the Controller. #1343

Closed bbqtk closed 4 years ago

bbqtk commented 4 years ago

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

My code looks like this, I will define it in the interface first and then implement it.

@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);
    }
}
截屏2020-03-17下午11 42 35

Describe what you expected to happen

I wrote the simplest request and found that Sentinel can do URL resources.

@RestController
public class SentinelController {

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

}
截屏2020-03-17下午11 40 45

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

The version and configuration I use are as follows

<dependency>
       <groupId>com.alibaba.cloud</groupId>
       <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
       <version>2.2.0.RELEASE</version>
</dependency>
spring.cloud.sentinel.transport.port=8719
spring.cloud.sentinel.transport.dashboard=localhost:8080
management.endpoints.web.exposure.include=*

Anything else we need to know?

I want to get a reply as soon as possible, because it affects a lot of things

cdfive commented 4 years ago

Adding this in the application.properties:

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

This is due to the default pattern /* in older version of spring-cloud-starter-alibaba-sentinel. It has been improved in the newest version, in which needn't add this config.

Related to #1279.

bbqtk commented 4 years ago

Thank you very much, this did solve my problem, hope it will be better!