我在尝试测试我的 UserRepository 时遇到问题,例如
principal.username = 'toto'
@Query("
FROM #{#entityName} entity
WHERE entity.username = ?#{principal.username}
")
我有一个例外
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'principal' cannot be found on object of type 'java.lang.Object[] - maybe not public or not valid?'
我的tdd类是UserRepositoryTest.class
有帮助
尝试
@Bean
EvaluationContextExtension securityExtension() {
return new SecurityEvaluationContextExtension();
}
在您的 AppConfig(或 test-appconfig)中。