java - 如何在不依赖 Pivotal GemFire 缓存的情况下启动 Spring Boot 应用程序

标签 java spring spring-boot geode spring-data-gemfire

我有一个 Spring Boot 应用程序,配置了 Pivotal GemFire ClientCache 实例及其相应的域对象。我还使用 Spring Boot Test 进行单元测试。对于每个测试用例执行,无论是通过类还是 Maven 构建,如果 GemFire 缓存关闭,Spring ApplicationContext 将无法加载。

如何在不依赖GemFire缓存的情况下启动Spring Boot应用程序?

最佳答案

我不确定我是否完全理解您的意思...

"For every test case execution, either through class or Maven build, Spring ApplicationContext fails to load if the GemFire cache is down."

您是否正在重新创建 ClientCache测试类中每个测试用例(方法)的实例?

如果是这样,那么这可能会很棘手,因为即使在调用 ClientCache.close() 之后也是如此。 ,GemFire可能还没有完全“关闭”并释放了ClientCache使用的所有资源。实例。然而,通常这并不能阻止 Spring ApplicationContext以免在后续测试用例执行时重新创建。它通常只会导致随后的测试失败,因为 ClientCache实例是脏的或过时的,保留上一个(或最后一个)测试用例执行的旧状态。

你是否也在使用Spring的@DirtiesContext也在你的测试用例方法上吗?

通常,明智的做法是循环使用 ApplicationContext每个测试类都有 GemFire 缓存实例(例如 ClientCache ),其中测试类中的每个测试用例方法将使用相同的 ApplicationContextClientCache实例;这是最理想的。

因此,我有两件事要与您分享:

  1. 首先,看看新的 Spring Boot for Apache Geode/Pivotal GemFire项目。文档是here 。我announced该项目已近一个月前推出。该项目采用“客户端”视角,使用 Pivotal GemFire 构建 Spring Boot 应用程序。也就是说,它给你一个自动配置的 ClientCache默认实例。

  2. 具体来说,请查看 Pivotal GemFire 的 Spring Boot 测试套件,从 here 开始。几乎所有这些测试类都使用 ClientCache实例并测试 Pivotal GemFire 的各个方面,例如 CQ 或安全性等。

  3. 在某些测试类中,我使用了“模拟”ClientCache实例(例如,这个 test class ,特别是这个 test configuration )。然而,在许多其他情况下,我使用了实时 GemFire ClientCache例如,对于 example或者这个test class ,这很有趣,因为这个测试类甚至 launches a server对于ClientCache要连接到的实例(测试本身)。

  4. Spring Boot for Apache Geode/Pivotal GemFire 中的所有测试协调逻辑均由另一个新项目 Spring Test for Apache Geode/Pivotal GemFire 提供。 。不幸的是,Apache Geode/Pivotal GemFire 的 Spring Test 很大程度上仍处于 WIP 阶段,因此还没有文档。不过,我广泛使用这个新的测试项目来测试 Apache Geode/Pivotal GemFire 的 Spring Boot。您将在扩展类中看到它的存在,例如 ForkingClientServerIntegrationTestsSupport 等等。

总之,使用新的 Spring Boot for Pivotal GemFireSpring Test for Pivotal GemFire 项目作为编写更有效的单元和集成测试的指南。

最后,如果您有一个重现您问题的 GitHub 存储库示例,我可以帮助您指出正确的方向。

希望这有帮助!

问候, 约翰

关于java - 如何在不依赖 Pivotal GemFire 缓存的情况下启动 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51510520/

相关文章:

Spring Boot 不会在端口 80 上启动

java - 如何使用 Jackson/其他库将 json 响应对象映射到首选格式?

java - Mongodb java输入两个日期字段之间的日期

java - 设计和对象责任的问题

java - 如何在列表中设置子项?

Spring Ldap - 多个基本名称

java - 无法计算表达式方法抛出 'org.hibernate.exception.GenericJDBCException' 异常

java - 加载屏幕 Libgdx Assetmanager

java - RestController POJO 中的 Spring 依赖注入(inject)

java - urlrewrite.xml 似乎不起作用