I have a rest controller API in a spring boot project. I need to add a common function, for example, validating the token of each incoming request before all the routes in that controller rather than calling the same function separately for each routes. Is there a way to achieve that with @Restcontroller based routing instead of going with web flux handler and router way?
Edit: Is there a way to use interceptors only for certain routes rather than all incoming requests?
Current version example:
@RestController
@RequestMapping("/api/")
class TestController() {
@GetMapping("/test1")
fun test1(): String {
common()
return "Test1"
}
@GetMapping("/test2")
fun test2(): String {
common()
return "Test2"
}
fun common() {
//some validation logic
}
}