Spring 筛选jpa内置rest资源
尝试公开存储库rest资源 我希望方法findAll和findById可以公开访问,即使用户没有连接,而其余的方法只有在经过身份验证的用户具有角色_ADMIN时才可以访问Spring 筛选jpa内置rest资源,spring,spring-boot,spring-security,spring-data-jpa,spring-data,Spring,Spring Boot,Spring Security,Spring Data Jpa,Spring Data,尝试公开存储库rest资源 我希望方法findAll和findById可以公开访问,即使用户没有连接,而其余的方法只有在经过身份验证的用户具有角色_ADMIN时才可以访问 @RepositoryRestResource @PreAuthorize("hasRole('ROLE_ADMIN')") public interface FilliereServices extends JpaRepository<Filliere, Integer> { @PreAuthorize
@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/Filliers无法按预期访问,但localhost:8080/Filliers/search/findAll抛出
org.springframework.data.rest.webmvc.ResourceNotFoundException
我在findAll上尝试了@RestResourcepath=findAll,但遇到了相同的问题。
然而,如果我只添加@queryfromfilliere,它就像一个符咒
有什么想法吗?如果覆盖JPA默认方法,则覆盖默认REST端点的行为。这些方法将不会显示在搜索路径下。
当您尝试访问localhost:8080/Filliers时使用findAll,当您调用localhost:8080/Filliers/{id}时使用findByIdInteger id。谢谢您提供的信息,是否有任何方法可以使它们显示在搜索路径下或不显示在搜索路径下,而不必使用@Query annotation标记它们?您必须使用不同的方法名称。例如,在不使用@Query的情况下,我可以使用什么作为名称使其与findAll具有相同的bevahior?findallbydisnotnull可以工作。您可以使用@RestResource将实际路径重命名为更简单的路径。