Spring Boot MVC request mapping overrides static resources
Asked Answered
M

1

2

I want to have rest controller in Spring Boot to handle all requests like this: "/{arg}", EXCEPT "/sitemap.xml". How can I achieve that?

Mathewson answered 18/1, 2017 at 17:5 Comment(0)
E
4

You could specify your request mapping on the controller level via regex and exclude some resources (e.g. 'excludeResourceA' and 'excludeResourceB') with:

@RestController
@RequestMapping(value = "/{arg:(?!sitemap.xml|excludeResourceA|excludeResourceB).*$}")
public class YourRestController {
    // your implementation
}

Of course you can also specify the request mapping on the method level with the same regex relative to your controller path matching and you can pass the argument with @PathVariable("arg") String arg in your method signature to your method body if you need it.

Egesta answered 18/1, 2017 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.