gs_vlad
gs_vlad

Reputation: 1449

Spring Boot MVC request mapping overrides static resources

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

Upvotes: 2

Views: 834

Answers (1)

Tom
Tom

Reputation: 1972

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.

Upvotes: 4

Related Questions