Getting REST version from request mapping of controller for mockmvc

When we write a spring rest controller we give version url and start writing different functions as endpoints like below @RestController @RequestMapping("/api/v1") public class ControllerApi { final LoginSender loginSender; public ControllerApi(LoginSender loginSender) { this.loginSender = loginSender; } @PostMapping("/login") boolean login(@RequestBody LoginParams params) { return loginSender.login(params.server(), params.login(), params.password(), params.build(), params.webManager()); } @GetMapping("/get1") LoginParams get1(@RequestParam String login, @RequestParam(required = false) String webMan, @RequestParam(required = false) String server, @RequestParam(required = false) String pass, @RequestParam(required = false) String build) { return LoginParams.builder() .webManager(webMan) .server(server) .password(pass) .login(login) .build(build) .build(); } } ib the future this controller will have different version number from v1 to v2 or in the future someone will change login endpoint from “/login” to “/loginJwt” but function order probably will not change. So in order to prevent your tests to fail we can collect these data from controller class like the code below. ...

December 12, 2022 · 2 min · Özkan Pakdil

Disable Spring Boot Hikari Datasource with aspectj

There is database which will shutdown in uncertain future and application wants to be restarted and still working after that. In spring boot every datasource bean depends to some other bean, if we use @ConditionalOnProperty which actually not creates the bean after that other beans fails to initialize and app stop booting. If need to disable a datasource without deleting all the spring beans or without using @ConditionalOnProperty When @ConditionalOnProperty comes to scene it is like deleting or changing all other spring beans which is not really required if you just want to disable a datasource. ...

August 4, 2022 · 1 min · Özkan Pakdil