1
发现我希望通过一个JPA查询来获取从CrudRepository
数据为RestResource
:春季安全主体不能从规划环境地政司
public interface IContactRepository extends PagingAndSortingRepository<Contact, Long> {
@Query("select contact from Contact contact where contact.owner.login = ?#{principal.username}")
@RestResource(path = "my")
List<Contact> findByOwner();
}
但我得到这个:
属性或字段“委托人”不能在类型 'java.lang.Object []'的对象上找到 - 可能不公开?
我可以得到本金直接:
SecurityContextHolder.getContext().getAuthentication().getPrincipal()
,但我需要它的界面里面去RestResource
直接访问。
看到这里。像你这样的Loks需要一些配置来启用它。 https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions#spel-evaluationcontext-extension-model –