I'm having a controller mapping as shown below
@RestController
@RequestMapping("/v1/connector")
public class Controller
and the API mapping as below
@GetMapping("2/auth")
when I hit the URL it's giving me the response as request URL not found. Can anyone tell why I'm getting this?
@GetMappingis a composed annotation that acts as a shortcut for@RequestMapping(method = RequestMethod. GET).@RequestMappingmaps HTTP requests to handler methods of MVC and REST controllers.When you use a base path on your controller class, all controllers in that class accept URL paths that start with your given base path. In your case:
This means all of the controllers inside this class have the base path of
/v1/connectorand this means is a constant part of your URL and cant be changed.So when you declare a
@GetMapping("2/auth"), Spring will automatically add a/at the beginning of your path if there was no/. And your path will behttp://YOUR-HOST-NAME/v1/connector/2/authinstead ofhttp://YOUR-HOST-NAME/v1/connector2/auth.See here for more clarification.
So If your application has paths like
/v1/connector1,/v1/connector2,/v1/connector3, etc. It means theconnector{n}is not constant and you must declare it on each of your controllers' methods separately.