【问题标题】:Unable to post to Spring Data Rest RepositoryRestResource in integration tests无法在集成测试中发布到 Spring Data Rest RepositoryRestResource
【发布时间】:2018-11-14 12:03:04
【问题描述】:

集成测试中没有显示资源链接对我的存储库公开。它们在应用程序运行时看起来很好,但在测试期间,应该是有效 uri 的 POST 会给出 404 和消息

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

配置

@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@DirtiesContext
@SpringBootTest(
    classes = {ServletWebServerFactoryAutoConfiguration.class, AnsApplication.class, PostgreSQLConfiguration.class},
    webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT
)
@DataJpaTest
@EnableJpaRepositories(basePackages = {"xxx.xxx.xxx"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)

请注意,此配置适用于使用注入存储库保存和检索实体的集成测试,问题是针对存储库发布。

【问题讨论】:

    标签: spring-boot spring-data-jpa spring-data-rest


    【解决方案1】:

    事实证明,与@DataJpaTest 注释有一些交互,还需要将ServletWebServerFactoryAutoConfiguration.class 添加到@SpringBootTest 列表中。这创建了一个没有注册我的端点的容器。

    从配置列表中删除 @DataJpaTestServletWebServerFactoryAutoConfiguration.class 允许我使用 TestRestTemplate 进行的集成测试工作。对于 JPA 特定的测试,我会将它们添加回来。

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 2018-11-19
      • 2017-03-29
      • 2017-04-27
      • 2020-04-04
      • 2019-02-27
      • 2016-08-19
      • 2015-08-13
      • 1970-01-01
      相关资源
      最近更新 更多