I'm using Spring Boot 1.3.1.RELEASE and trying to create a custom Repository + Controller. I configured the basePath to be /api and cannot figure out how to put the custom Controller's URI to automatically be relative to basePath. Is there some piece of magic I'm missing?
Here's the controller. I've tried every combination of the attributes below as well. I left in the commented out ones so you can see what I've tried.
@RepositoryRestController
// @Controller
@ExposesResourceFor(AnalystSummaryModel.class)
// @RequestMapping("/analystsummaries")
public class AnalystSummaryController {
@Autowired
AnalystSummaryRepository repository;
@Autowired
private AnalystSummaryResourceAssembler resourceAssembler;
@ResponseBody
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public PagedResources<AnalystSummaryModel> getAnalystSummaries(
final Pageable pageable,
final PagedResourcesAssembler assembler) {
final Page<AnalystSummaryModel> analystSummaries = repository.findAll(pageable);
return assembler.toResource(analystSummaries, resourceAssembler);
}
}
I also create a ResourceProcessor based on another question.
When I view the /api endpoint, I see the following:
{
"_links" : {
"self" : {
"href" : "http://localhost:8080"
},
"profile" : {
"href" : "http://localhost:8080/api/profile"
}
}
}
When I uncomment the @RequestMapping, I then get:
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/analystsummaries"
},
"profile" : {
"href" : "http://localhost:8080/api/profile"
}
}
}
What am I missing to have the mapping be relative to basePath, which I set in application.yml to the following?
spring.data.rest.base-path: /api
Some more information:
Using @BasePathAware actually results in this controller service two different URIs! It shows up at / as well as /api/analystSummaries (because of the auto-pluralization, etc). Then when using ControllerLinkBuilder it uses the path of the first. So my updated question is: Why is this exposed twice? How can I eliminate the implicit root (since there is no @RequestMapping) and keep the one that is under /api?