对于最新稳定版本,请使用 Spring Boot 4.0.4spring-doc.cadn.net.cn

Hazelcast

如果 Hazelcast 在类路径上且找到了合适的配置,Spring Boot 会自动配置一个 HazelcastInstance,您可以将其注入到应用程序中。spring-doc.cadn.net.cn

Spring Boot 首先尝试通过检查以下配置选项来创建一个客户端:spring-doc.cadn.net.cn

如果无法创建客户端,Spring Boot 会尝试配置一个嵌入式服务器。 如果您定义了一个 Config Bean,Spring Boot 将直接使用它。 如果您的配置定义了一个实例名称,Spring Boot 会尝试定位现有实例,而不是创建新实例。spring-doc.cadn.net.cn

您也可以通过配置指定要使用的Hazelcast配置文件,例如如下示例所示:spring-doc.cadn.net.cn

spring.hazelcast.config=classpath:config/my-hazelcast.xml
spring:
  hazelcast:
    config: "classpath:config/my-hazelcast.xml"

Otherwise, Spring Boot tries to find the Hazelcast configuration from the default locations: hazelcast.xml in the working directory or at the root of the classpath, or a YAML counterpart in the same locations. We also check if the hazelcast.config system property is set. See the Hazelcast 文档 for more details.spring-doc.cadn.net.cn

默认情况下,支持在 Hazelcast 组件上使用 @SpringAware。 可以通过声明一个 HazelcastConfigCustomizer Bean 并重写 ManagedContext,该 Bean 的 @Order 需大于零。
Spring Boot 还提供对 Hazelcast 的 显式缓存支持。 如果启用了缓存,HazelcastInstance 将自动被包装在 CacheManager 实现中。