java Spring数据REST存储库404
我有带Spring Data REST的Spring Boot应用程序
我有以下课程:
用于身份验证的数据JPA存储库:
public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(String username);
}
API使用的安全数据REST存储库:
@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);
}
存储库REST配置器适配器:
@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);
}
}
问题是,当我启动应用程序时,API的数据REST存储库有时不可用。我猜这是因为Spring用第一个JPA存储库为type User重写了存储库bean
在Actuator beans endpoint中,我可以看到这两个bean,即使REST API显示404 for/users页面
同样,这种行为对我来说是不可预测的——有时有效,有时无效
您知道如何告诉Spring使用确切的bean进行数据REST吗
提前谢谢
# 1 楼答案
经过一些调查,我发现了完全相同的问题
另见this one
最后,我将两个存储库合并为一个,解决了我的问题。但这绝对不是我喜欢的方式