> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/38.-hazelcast.md).

# 38. Hazelcast

如果添加[Hazelcast](https://hazelcast.com/)依赖并正确配置好了，Spring Boot将自动配置一个`HazelcastInstance`，你可以注入到应用中。

如果定义了`com.hazelcast.config.Config` bean，则Spring Boot将使用它。如果你的配置指定了实例的名称，Spring Boot将尝试定位已存在的而不是创建一个新实例。你可以在配置中指定将要使用的`hazelcast.xml`配置文件：

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

否则，Spring Boot尝试从默认路径查找Hazelcast配置，也就是`hazelcast.xml`所在的工作路径或classpath的根路径。Spring Boot也会检查是否设置`hazelcast.config`系统属性，具体参考[Hazelcast文档](http://docs.hazelcast.org/docs/latest/manual/html-single/)。

如果`hazelcast-client`存在于类路径中，Spring Boot将会首先尝试使用与上面相似的规则创建一个客户端，也就是：

* 一个`com.hazelcast.client.config.ClientConfig`bean
* 由`spring.hazelcast.config`属性定义的配置文件
* `hazelcast.client.config`系统属性
* 一个在工作目录或者类路径的根目录中的`hazelcast-client.xml`

**注** Spring Boot[为Hazelcast提供了缓存支持](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-hazelcast)。如果开启缓存的话，`HazelcastInstance`实例将自动包装进一个`CacheManager`实现中。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/38.-hazelcast.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
