Spring DataJpaTest 与存储库和 SpEl 语言

问题描述 投票:0回答:1

我在尝试测试我的 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

有帮助

java spring spring-security spring-data-jpa
1个回答
0
投票

尝试

@Bean
EvaluationContextExtension securityExtension() {
    return new SecurityEvaluationContextExtension();
}

在您的 AppConfig(或 test-appconfig)中。

© www.soinside.com 2019 - 2024. All rights reserved.