【发布时间】:2019-11-08 05:41:33
【问题描述】:
试图公开存储库休息资源。
我希望 findAll() 和 findById() 方法是公开的(即使用户未连接也可访问),其余方法仅在经过身份验证的用户具有 ROLE_ADMIN 时才可访问
@RepositoryRestResource
@PreAuthorize("hasRole('ROLE_ADMIN')")
public interface FilliereServices extends JpaRepository<Filliere, Integer> {
@PreAuthorize("permitAll")
public List<Filliere> findAll();
@PreAuthorize("permitAll")
public Optional<Filliere> findById(Integer id);
}
localhost:8080/fillieres 无法按预期访问,但是 localhost:8080/fillieres/search/findAll 抛出一个
org.springframework.data.rest.webmvc.ResourceNotFoundException
我在findAll() 上尝试过@RestResource(path="findAll"),但同样的问题。
但是,如果我只添加@Query("FROM Filliere"),它就像一个魅力。
有什么想法吗?
【问题讨论】:
标签: spring spring-boot spring-security spring-data-jpa spring-data