Skip to content

@RepsitoryRestController adds the repository twice (under root and basePath) [DATAREST-972] #1342

@spring-projects-issues

Description

@spring-projects-issues

Robert Rackl opened DATAREST-972 and commented

GIVEN a spring-data-rest app, that exposes some repository as HATEOAS REST endpoints.

WHEN you now want to override the behaviour of a response handler, this is described in the spring-data doc:
http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers

BUT this does not work. Here are two related posts that describe the inconsistency:

The simplest test I could find was: When you create a controller with the @BasePathAwareController annotation, then

  • you MUST ONLY set the @RequestMapping at the class level ans MUST NOT set it at method / type level (which is not documented yet) for it to work at all
  • but then still the controller is added twice: at root level and with basePath prefix.

Here is my code:

@RepositoryRestController    
@RequestMapping("postBallotJson")
public class BallotRestController {
  @Autowired
  BallotRepo ballotRepo;
 
  @RequestMapping(method = POST)  
  public @ResponseBody PersistentEntityResource postBallot(@RequestBody Resource<BallotModel> newBallotRes,
                            PersistentEntityResourceAssembler resourceAssembler)
  {
    log.trace("=> POST /ballot "+newBallotRes);
    BallotModel newBallot = newBallotRes.getContent();
     [... do some additinal customization with  newBallot .. ]
     BallotModel createdBallot = ballotRepo.save(newBallot);
     return resourceAssembler.toResource(createdBallot);
  }

When I start the app I see in the log:

Mapped "{[/postBallotJson],methods=[POST]}" onto public org.springframework.http.ResponseEntity org.doogie.liquido.rest.BallotRestController.postBallot(org.doogie.liquido.model.BallotModel,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler)

and also further down  (/liquido/v2/   is my basePath)

Mapped "{[/liquido/v2/postBallotJson],methods=[POST]}" onto public org.springframework.http.ResponseEntity org.doogie.liquido.rest.BallotRestController.postBallot(org.doogie.liquido.model.BallotModel,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler)

And only the resource in the root path /postBallotJson works.

Expected Behaviour

The resource with the base path prefix should be the only one and work. /liquido/v2/postBallotJson


Affects: 2.5.4 (Hopper SR4)

Reference URL: https://github.com/mike-boddin/spring-data-rest-example

6 votes, 10 watchers

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions