I want to override @RepositoryRestResource autogenerated controller methods using @RepositoryRestController having set the SDR's Base Path to "/api".
Spring Data Rest 3.0 (and earlier) says:
"This controller [as shown in the snippet] will be served from the same API base path defined in RepositoryRestConfiguration.setBasePath that is used by all other RESTful endpoints (e.g. /api)". https://docs.spring.io/spring-data/rest/docs/3.0.1.RELEASE/reference/html/#customizing-sdr.overriding-sdr-response-handlers (chapter 15.4)
This code snippet DOES NOT have a @RequestMapping on the class level, though.
My SDR app is configured with RepositoryRestConfiguration object
config.setBasePath("/api"); and yet @RepositoryRestController doesn't override SDR's autogenerated controller methods.
Please consider the accepted answear to this post: Spring Data Rest controllers: behaviour and usage of @BasePathAwareController, @RepositoryRestController, @Controller and @RestController
Please help me understand this! :)
AppConf.java:
@Configuration @Import(value = {DataConf.class}) @EnableWebMvc @ComponentScan(value = "pl.mydomain.controller") public class AppConf { @Bean public RepositoryRestConfigurer repositoryRestConfigurer() { return new RepositoryRestConfigurerAdapter() { public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.setBasePath("/api"); } }; } } TokenController.java:
@RepositoryRestController public class TokenController { private TokenRepository repository; @Autowired public TokenController(TokenRepository tokenRepository) { this.repository = tokenRepository; } @RequestMapping(method = GET, path = "/tokens") public @ResponseBody ResponseEntity<?> tokens() { return ResponseEntity.ok("Hello"); } } TokenRepository.java:
@RepositoryRestResource(path = "tokens") public interface TokenRepository extends CrudRepository<Token, Long>{ }