spring-projects / spring-projects/spring-data-rest

Documentation uses incorrect annotation in the code example

Open
#2,352 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jan 22, 2024.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Hi

Current documentation section that describes overriding default response handlers (https://docs.spring.io/spring-data/rest/reference/customizing/overriding-sdr-response-handlers.html) states multiple times that @RepositoryRestController annotation should be used:

Sometimes, you may want to write a custom handler for a specific resource. To take advantage of Spring Data REST’s settings, message converters, exception handling, and more, use the @RepositoryRestController annotation instead of a standard Spring MVC @Controller or @RestController. Controllers annotated with @RepositoryRestController are served from the API base path defined in RepositoryRestConfiguration.setBasePath, which is used by all other RESTful endpoints (for example, /api). The following example shows how to use the @RepositoryRestController annotation:

However in the code block after this text @BasePathAwareController annotation is used:

@BasePathAwareController
class ScannerController {

  private final ScannerRepository repository;

  ScannerController(ScannerRepository repository) { 
    repository = repository;
  }

  @GetMapping(path = "/scanners/search/producers") 
  ResponseEntity<?> getProducers() {

    List<String> producers = repository.listProducers(); 

    //
    // do some intermediate processing, logging, etc. with the producers
    //

    CollectionModel<String> resources = CollectionModel.of(producers); 

    resources.add(linkTo(methodOn(ScannerController.class).getProducers()).withSelfRel()); 

    // add other links as needed

    return ResponseEntity.ok(resources); 
  }
}

Spring Data REST: 4.2.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.