0

I'm having an strange behaviour with the creation of spring data rest endpoints e.g. Repositories annotated with @RepositoryRestResource.

The same war file started in the same tomcat caontainer sometimes creates a endpoint, sometimes it doesn't. I've checked the Dependency tree but could not find any duplicates or version conflicts.

I have a repository class

public interface  ARepository extends DefaultProjectRepository<A, Long>, JpaSpecificationExecutor<BoardnetProject> {
  Optional<A> findByX(String value);
}

And some default interface to handle authorization:

public interface DefaultProjectRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
   @PreAuthorize("hasAnyRole('ROLE_EDITOR,ROLE_ADMIN')")
   @Override
   <S extends T> S save(S entity);

   //...       
}

And then I have a controller which should be accessible through the same path like the repository resource:

 @RepositoryRestController
 @RequestMapping("/")
 public class ARepositoryController {

    @GetMapping("a/search/findSomeSpecial")
    public ResponseEntity<A> someSpecialFindMethod() {
      // ...
    }
 }

Using @RepositoryRestResource instead of @RestController is intended here.

I also have some more casual rest controllers:

 @RestController
 public class SimpleController {
    @GetMapping("/some/path/to/b")
    public ResponseEntity<B> getB() { //.... }
 }

The problem now I am facing is, that sometimes the endpoints for ARepository are generated and sometimes they are not.

Someone having any idea? Thanks a lot for your time!

  • Does this answer your question? [Difference between @RestController and @RepositoryRestController](https://stackoverflow.com/questions/34512878/difference-between-restcontroller-and-repositoryrestcontroller) – Alan Hay Dec 02 '19 at 20:54
  • `@RepositoryRestResource`? I think you want `@RepositoryRestController` – Alan Hay Dec 02 '19 at 20:55
  • @alan: True, I used `@RepositoryRestController` to annotate the controller and `@RepositoryRestResource` to annotate the repository. I corrected the code snippet in the question. – Christoph Ehscheidt Dec 03 '19 at 08:42

0 Answers0