【问题标题】:Spring IT test fails春季 IT 测试失败
【发布时间】:2020-12-15 03:09:09
【问题描述】:

我在我的 spring(不是 spring boot)应用程序中添加了一个新的 querydsl 控制器方法。

@GetMapping("/watcher")
@ResponseBody
public List<Watcher> getWatchers(final Predicate predicate) {
  return repo.findAll(predicate);
}

我还在我的 WebMvcConfigurer 实现中添加了以下注释:

@EnableSpringDataWebSupport

应用程序按预期使用这个新端点。我现在想添加一个 Spring IT 测试来测试这个新特性。

这是测试:

@Test
public void test() {
  mvc.perform(get("/watcher"));
}

测试类包含以下注解:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringITConfig.class)
@WebAppConfiguration

其他测试存在于同一类中,perform() 适用于这些测试,但这是我第一次向 querydsl 控制器添加测试。

测试失败,No primary or default constructor found for interface com.querydsl.core.types.Predicate

我尝试将注释 @EnableSpringDataWebSupport 添加到我的测试中,但它并没有改变任何东西。

我错过了什么?

谢谢

【问题讨论】:

  • 你检查过这篇帖子stackoverflow.com/questions/50679551/… ??
  • 是的,它说要将注释 EnableSpringDataWebSupport 也添加到测试中,正如我在问题中提到的那样,但它不会改变结果

标签: java spring spring-mvc spring-data querydsl


【解决方案1】:

尝试删除您的 @ContextConfiguration 并将其替换为 @SpringApplicationConfiguration(classes = YOUR_MAIN_APP_CLASS) 以引导所有需要的查询 dsl 存储库,以及您的谓词类的正确杰克逊映射器。

【讨论】:

  • 正如我在问题中所说,我不使用弹簧靴。我没有主课。
猜你喜欢
  • 2016-12-13
  • 2016-03-03
  • 2018-11-05
  • 2011-09-26
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
  • 2022-10-14
  • 2016-06-07
相关资源
最近更新 更多