spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
914 stars 560 forks source link

@RepositoryRestController seems to not work [DATAREST-991] #1356

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Dimitri KOPRIWA opened DATAREST-991 and commented

It appear the repository rest controller annotation isn't working in spring-data.

Expected

to return a resource under basePath /api/greg

Result

404 Page not found

Step to reproduce

Clone project

git clone git@github.com:spring-guides/tut-react-and-spring-data-rest.git && cd tut-react-and-spring-data-rest/security

Install deps

./mvnw install

Create the file ManagerController.java under src/main/java/

@RepositoryRestController
public class ManagerController {

    @Autowired
    private ManagerRepository managerRepository;

    @Autowired
    public TestController(ManagerRepository managerRepository) {
        this.managerRepository = managerRepository;
    }

    @RequestMapping(value = "/greg")
    public ResponseEntity<Resource<Manager>> index() {
        Manager greg = this.managerRepository.findByName("greg");
        Resource<Manager> resource = new Resource<>(greg);
        return ResponseEntity.ok(resource);
    }

}

Run

./mvnw spring-boot:run

Open your browser and hit http://localhost:8080/api/greg

Version

Spring-boot 1.4.2.RELEASE

Demo

git clone git@github.com:kopax/DATAREST-991.git && cd DATAREST-991
./mvnw install
./mvnw spring-boot:run

The project is a clone of the security directory of this repository https://github.com/spring-guides/tut-react-and-spring-data-rest

The only file I've created is ManagerController.java https://github.com/kopax/DATAREST-991/blob/master/src/main/java/com/greglturnquist/payroll/ManagerController.java


Affects: 2.6 GA (Ingalls), 2.5.7 (Hopper SR7)

2 votes, 4 watchers

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

That's weird, as we definitely have test cases for that. Would you mind attaching an example that shows the problem?

spring-projects-issues commented 7 years ago

Dimitri KOPRIWA commented

I have updated the issue with a github containing the running example

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

Thanks for that but having to run an app and executing manual steps to get to something at somepoint is not something we usually investigate. Ideally, I get a sample that doesn't include any unrelated parts (React, Node etc.) and I can run mvn clean test to see a test fail

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

Couple of remarks:

I guess we need to do a better job of documenting how to use these annotations

spring-projects-issues commented 6 years ago

Guram Savinov commented

Documentation says clearly that you sohuld use @RepositoryRestController to (quote) "plug-in a custom handler for a Spring Data finder method".

Moreover, there is a note:

In this example, the combined path will be RepositoryRestConfiguration.getBasePath() + /scanners/search/listProducers.

In SDR 2.6.11.RELEASE it works: @RepositoryRestController appends base path as it described.

One more concern:

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

Does your suggestion to use @BasePathAwareController instead of @RepositoryRestController means that we loose features mentioned above (like message converters, exception handling etc.)?

spring-projects-issues commented 3 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.