I have developed a SpringBoot REST API with many controllers, using @RequestMapping annotation. I want to create some kind of global variable to store:
String firstPartUrl = "/api/"
String apiVersion = "v1/"
So that in each controller's request mapping I can put:
@RestController
@RequestMapping(firstPartUrl apiVersion "/tubas")
public class TubaController {
}
This way, when the API version increases, I only need to change one value.
Thanks for your help.
CodePudding user response:
Add to application.properties
@RestController
@RequestMapping("${firstPartUrl}" "${apiVersion}" "/tubas")
public class TubaController {
}
application.properties
firstPartUrl="/blabla"
apiVersion="/v2"
