|
对于最新稳定版本,请使用 Spring Boot 4.0.4! |
Hazelcast
如果 Hazelcast 在类路径上且找到了合适的配置,Spring Boot 会自动配置一个 HazelcastInstance,您可以将其注入到应用程序中。
Spring Boot 首先尝试通过检查以下配置选项来创建一个客户端:
-
存在一个
ClientConfigBean。 -
由
spring.hazelcast.config属性定义的配置文件。 -
hazelcast.client.config系统属性的存在。 -
一个在工作目录中的
hazelcast-client.xml 文件,或者位于类路径的根目录下。 -
一个在工作目录中的
hazelcast-client.yaml (或hazelcast-client.yml )文件,或者类路径的根目录下。
如果无法创建客户端,Spring Boot 会尝试配置一个嵌入式服务器。
如果您定义了一个 Config Bean,Spring Boot 将直接使用它。
如果您的配置定义了一个实例名称,Spring Boot 会尝试定位现有实例,而不是创建新实例。
您也可以通过配置指定要使用的Hazelcast配置文件,例如如下示例所示:
-
Properties
-
YAML
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.
默认情况下,支持在 Hazelcast 组件上使用 @SpringAware。
可以通过声明一个 HazelcastConfigCustomizer Bean 并重写 ManagedContext,该 Bean 的 @Order 需大于零。 |
Spring Boot 还提供对 Hazelcast 的 显式缓存支持。
如果启用了缓存,HazelcastInstance 将自动被包装在 CacheManager 实现中。 |