如果Spring security位于类路径上,java无法使用@DataJpaTest
我正在尝试更新我的测试用例以使用@DataJpaTest
。然而,我遇到了一些似乎与Spring安全性相关的问题。下面是测试类的一个示例
@RunWith(SpringRunner.class)
@DataJpaTest
public class ExampleRepositoryTest {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Inject
private ExampleRepository repository;
@Test
public void test() throws Exception {
...
}
由于缺少bean org.springframework.security.config.annotation.ObjectPostProcessor
,我一直得到错误java.lang.IllegalStateException: Failed to load ApplicationContext
该项目是一个具有Spring安全性的RESTful应用程序。原始测试用例使用@SpringBootTest
创建了一个完整的Spring引导上下文。@DataJpaTest
应该帮助我测试JPA切片,这正是我想要的
任何帮助都将不胜感激。我错过了什么
# 1 楼答案
我也犯了同样的错误。 对于我的例子,我在同一个类上添加了
@SpringBootApplication
和@EnableResourceServer
。 当我将@EnableResourceServer
移动到另一个配置类时,错误消失了