Spring Data REST repository 404 from time to time

Viewed 1482

I have the Spring Boot application with Spring Data REST.

I have the following classes in it:

Data JPA repository for authentication purposes:

public interface UserRepository extends JpaRepository<User, Long> {
    User findByUsername(String username);
}

Secured Data REST repository for API usages:

@RepositoryRestResource
@Secured(Role.ROLE_USER_READ)
public interface UserDataRestRepository extends PagingAndSortingRepository<User, Long> {
    @Override
    @Secured(Role.ROLE_USER_WRITE)
    <S extends User>S save(S entity);

    @Override
    @Secured(Role.ROLE_USER_DELETE)
    void delete(Long id);
}

Repository REST configurer adapter:

@Configuration
public class RepositoryRestConfig extends RepositoryRestConfigurerAdapter {
    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.setRepositoryDetectionStrategy(RepositoryDetectionStrategies.ANNOTATED);
        config.setReturnBodyOnCreate(true);
        config.setReturnBodyOnUpdate(true);
        config.setReturnBodyForPutAndPost(true);
    }
}

The problem is when I start up my application, Data REST repository for API is unavailable from time to time. I guess it's because Spring rewrites repository bean for type User with the first JPA repository.

In Actuator beans endpoint I can see both beans even if REST API says 404 for /users page.

Again, this behavior is unpredictable for me - sometimes it works, sometimes doesn't.

Do you know the way how to tell to Spring to use the exact bean for Data REST?

Thanks in advance.

1 Answers
Related