> 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/30.-working-with-nosql-technologies/30.8-couchbase/30.8.2-spring-data-couchbase-repositories.md).

# 30.8.2 Spring Data Couchbase仓库

Spring Data包含的仓库也支持Couchbase，具体可查看Spring Data Couchbase的[参考文档](https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/)。

你可以注入一个自动配置的`CouchbaseTemplate`实例，就像注入其他Spring Bean那样，只要默认的`CouchbaseConfigurer`可以使用。

下面的例子展示了怎么样注入一个Couchbase bean：

```java
@Component
public class MyBean {

    private final CouchbaseTemplate template;

    @Autowired
    public MyBean(CouchbaseTemplate template) {
        this.template = template;
    }

    // ...

}
```

你可以在你自己的配置中定义一些bean，来覆盖自动配置中提供的那些：

* `CouchbaseTemplate` `@Bean` ，称为`couchbaseTemplate`
* `IndexManager` `@Bean`，称为`couchbaseIndexManager`
* `CustomConversions` `@Bean`，称为`couchbaseCustomConversions`

为了避免在你的配置中硬编码那些名字，你可以重复使用由Spring Data Couchbase提供的`BeanNames`。例如，你可以像下面这样自定义要使用的转换器：

```java
@Configuration
public class SomeConfiguration {

    @Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
    public CustomConversions myCustomConversions() {
        return new CustomConversions(...);
    }

    // ...

}
```

**提示** 如果想完全关闭Spring Data Couchbase的自动配置，你可以提供自己的`org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration`实现。
