I'm looking to define /api
as the root context for all my @RestController
s and don't want to specify it for each of them.
For instance, I would like to write @RestController("/clients")
instead of @RestController("/api/clients")
and make my request mappings available at /api/clients
but have my static resources (in /main/resources/static
) still served at /**
.
So, setting server.servlet.contextPath=/api
in application.properties
is not a solution for my use case because the static resources will be served at /api
, which I don't want.
In brief, I would like to have the same feature as JAX-RS @ApplicationPath("/api")
in Spring Web MVC, is this possible?
One of the possible solution(work around) is to use Parent Class with mapping
@RequestMapping(path="/api")
abstract class BaseController{
....
}
Other controllers can extend it
class OtherController extends BaseController {
@RequestMapping(path="/clients")
public ....clients(....){
.....
}
}
Please note that @RequestMapping will get overridden if you place it on top of any child class. Like explained here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With