# 79.12 配置JPA使用的组件

如果想配置一个JPA使用的组件，你需要确保该组件在JPA之前初始化。组件如果是Spring Boot自动配置的，Spring Boot会为你处理。例如，Flyway是自动配置的，Hibernate依赖于Flyway，这样Hibernate有机会在使用数据库前对其进行初始化。

如果自己配置组件，你可以使用`EntityManagerFactoryDependsOnPostProcessor`子类设置必要的依赖，例如，如果你正使用Hibernate搜索，并将Elasticsearch作为它的索引管理器，这样任何`EntityManagerFactory` beans必须设置为依赖`elasticsearchClient` bean：

```java
/**
 * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that
 * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean.
 */
@Configuration
static class ElasticsearchJpaDependencyConfiguration
        extends EntityManagerFactoryDependsOnPostProcessor {

    ElasticsearchJpaDependencyConfiguration() {
        super("elasticsearchClient");
    }

}
```


---

# Agent Instructions: 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:

```
GET https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/79.-data-access/79.12-configure-a-component-that-is-used-by-jpa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
