spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Getmapping annotation matching regular expression does not take effect

Open VitaminCtea opened this issue 3 years ago • 2 comments

When practicing spring MVC, I wrote it once according to the official example. As a result, a 400 service error status code appears when I jump to the URL matching the specified regular expression!

When I jump to http://localhost:8080/persons/spring -Web-3.0.5.jar address, an error request will occur!

The specific description of the error is that the server cannot or will not process the current request because it is considered that the client has made an error (for example, malformed request syntax, invalid request information frames, or virtual request routing).

I don't know how to solve it. These codes are the same as the official codes, and using the requestmapping annotation also has the same effect.

The code is as follows:

@Controller
@RequestMapping("/persons")
public class PersonController {

    // ...
    // jump to http://localhost:8080/persons/spring -Web-3.0.5.jar
    @GetMapping(value = "/{name:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{ext:\\.[a-z]+}")
    public void handle(@PathVariable String name, @PathVariable String version, @PathVariable String ext) {
        System.out.printf("Matching address: /persons/spring-web-3.0.5.jar -> %s%s%s%n", name, version, ext);
    }
}

How can I solve it? In addition, the display page uses viewresolver, so the restcontroller annotation is not used! But using the restcontroller annotation can't change anything!

VitaminCtea avatar Sep 11 '22 02:09 VitaminCtea

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

poutsma avatar Sep 14 '22 13:09 poutsma

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Sep 21 '22 14:09 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Sep 28 '22 14:09 spring-projects-issues