【发布时间】:2017-10-18 01:24:49
【问题描述】:
我有带有 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 存储库重写了 User 类型的存储库 bean。
在执行器 bean 端点中,即使 REST API 显示 /users 页面的 404,我也可以看到两个 bean。
同样,这种行为对我来说是不可预测的 - 有时有效,有时无效。
您知道如何告诉 Spring 将确切的 bean 用于 Data REST 吗?
提前致谢。
【问题讨论】:
标签: java spring spring-boot spring-data-jpa spring-data-rest