# 79.10 使用Spring Data JPA和Mongo仓库

Spring Data JPA和Spring Data Mongo都能自动为你创建`Repository`实现。如果它们同时出现在类路径下，你可能需要添加额外的配置来告诉Spring Boot你想要创建哪个仓库。最明确的方式是使用标准的Spring Data `@EnableJpaRepositories`与`@EnableMongoRepositories`，然后提供它你的`Repository`接口的位置。

这里也有`spring.data.*.repositories.enabled`与`spring.data.*.repositories.type`标志，可用来在外部配置中开启或关闭仓库的自动配置。这在你想关闭Mongo仓库但仍使用自动配置的`MongoTemplate`时非常有用。

相同的障碍和特性也存在于其他自动配置的Spring Data仓库类型（Elasticsearch、Solr等），只需要改变对应注解的名称和标志。


---

# 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.10-use-spring-data-jpa-and-mongo-repositories.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.
