Reinstate support for Spring Data Couchbase

Closes gh-28976
This commit is contained in:
Andy Wilkinson
2021-12-10 14:28:20 +00:00
parent 799af76c08
commit 1dbfcf8b57
56 changed files with 2113 additions and 13 deletions

View File

@@ -258,6 +258,7 @@ boot-features-connecting-to-cassandra=features.nosql.cassandra.connecting
boot-features-spring-data-cassandra-repositories=features.nosql.cassandra.repositories
boot-features-couchbase=features.nosql.couchbase
boot-features-connecting-to-couchbase=features.nosql.couchbase.connecting
boot-features-spring-data-couchbase-repositories=features.nosql.couchbase.repositories
boot-features-ldap=features.nosql.ldap
boot-features-ldap-connecting=features.nosql.ldap.connecting
boot-features-ldap-spring-data-repositories=features.nosql.ldap.repositories
@@ -270,6 +271,7 @@ boot-features-caching-provider-generic=features.caching.provider.generic
boot-features-caching-provider-jcache=features.caching.provider.jcache
boot-features-caching-provider-hazelcast=features.caching.provider.hazelcast
boot-features-caching-provider-infinispan=features.caching.provider.infinispan
boot-features-caching-provider-couchbase=features.caching.provider.couchbase
boot-features-caching-provider-redis=features.caching.provider.redis
boot-features-caching-provider-caffeine=features.caching.provider.caffeine
boot-features-caching-provider-simple=features.caching.provider.simple
@@ -766,6 +768,7 @@ features.caching.provider.generic=io.caching.provider.generic
features.caching.provider.jcache=io.caching.provider.jcache
features.caching.provider.hazelcast=io.caching.provider.hazelcast
features.caching.provider.infinispan=io.caching.provider.infinispan
features.caching.provider.couchbase=io.caching.provider.couchbase
features.caching.provider.redis=io.caching.provider.redis
features.caching.provider.caffeine=io.caching.provider.caffeine
features.caching.provider.simple=io.caching.provider.simple
@@ -882,6 +885,7 @@ features.nosql.cassandra.connecting=data.nosql.cassandra.connecting
features.nosql.cassandra.repositories=data.nosql.cassandra.repositories
features.nosql.couchbase=data.nosql.couchbase
features.nosql.couchbase.connecting=data.nosql.couchbase.connecting
features.nosql.couchbase.repositories=data.nosql.couchbase.repositories
features.nosql.ldap=data.nosql.ldap
features.nosql.ldap.connecting=data.nosql.ldap.connecting
features.nosql.ldap.repositories=data.nosql.ldap.repositories

View File

@@ -57,6 +57,8 @@
:spring-data: https://spring.io/projects/spring-data
:spring-data-cassandra: https://spring.io/projects/spring-data-cassandra
:spring-data-commons-api: https://docs.spring.io/spring-data/commons/docs/{spring-data-commons-version}/api/org/springframework/data
:spring-data-couchbase: https://spring.io/projects/spring-data-couchbase
:spring-data-couchbase-docs: https://docs.spring.io/spring-data/couchbase/docs/{spring-data-couchbase-version}/reference/html/
:spring-data-elasticsearch: https://spring.io/projects/spring-data-elasticsearch
:spring-data-elasticsearch-docs: https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/
:spring-data-envers: https://spring.io/projects/spring-data-envers

View File

@@ -8,6 +8,7 @@ Spring Data provides additional projects that help you access a variety of NoSQL
* {spring-data-redis}[Redis]
* {spring-data-gemfire}[GemFire] or {spring-data-geode}[Geode]
* {spring-data-cassandra}[Cassandra]
* {spring-data-couchbase}[Couchbase]
* {spring-data-ldap}[LDAP]
Spring Boot provides auto-configuration for Redis, MongoDB, Neo4j, Solr, Elasticsearch, Cassandra, Couchbase, LDAP and InfluxDB.
@@ -455,7 +456,9 @@ TIP: For complete details of Spring Data Cassandra, see the https://docs.spring.
[[data.nosql.couchbase]]
=== Couchbase
https://www.couchbase.com/[Couchbase] is an open-source, distributed, multi-model NoSQL document-oriented database that is optimized for interactive applications.
Spring Boot offers auto-configuration for Couchbase.
Spring Boot offers auto-configuration for Couchbase and the abstractions on top of it provided by https://github.com/spring-projects/spring-data-couchbase[Spring Data Couchbase].
There are `spring-boot-starter-data-couchbase` and `spring-boot-starter-data-couchbase-reactive` "`Starters`" for collecting the dependencies in a convenient way.
[[data.nosql.couchbase.connecting]]
@@ -493,6 +496,45 @@ To take more control, one or more `ClusterEnvironmentBuilderCustomizer` beans ca
[[data.nosql.couchbase.repositories]]
==== Spring Data Couchbase Repositories
Spring Data includes repository support for Couchbase.
For complete details of Spring Data Couchbase, see the {spring-data-couchbase-docs}[reference documentation].
You can inject an auto-configured `CouchbaseTemplate` instance as you would with any other Spring Bean, provided a `CouchbaseClientFactory` bean is available.
This happens when a `Cluster` is available, as described above, and a bucket name has been specified:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
couchbase:
bucket-name: "my-bucket"
----
The following examples shows how to inject a `CouchbaseTemplate` bean:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/nosql/couchbase/repositories/MyBean.java[]
----
There are a few beans that you can define in your own configuration to override those provided by the auto-configuration:
* A `CouchbaseMappingContext` `@Bean` with a name of `couchbaseMappingContext`.
* A `CustomConversions` `@Bean` with a name of `couchbaseCustomConversions`.
* A `CouchbaseTemplate` `@Bean` with a name of `couchbaseTemplate`.
To avoid hard-coding those names in your own config, you can reuse `BeanNames` provided by Spring Data Couchbase.
For instance, you can customize the converters to use, as follows:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/nosql/couchbase/repositories/MyCouchbaseConfiguration.java[]
----
[[data.nosql.ldap]]
=== LDAP
https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol[LDAP] (Lightweight Directory Access Protocol) is an open, vendor-neutral, industry standard application protocol for accessing and maintaining distributed directory information services over an IP network.

View File

@@ -42,6 +42,7 @@ If you have not defined a bean of type `CacheManager` or a `CacheResolver` named
. <<io#io.caching.provider.generic,Generic>>
. <<io#io.caching.provider.jcache,JCache (JSR-107)>> (Hazelcast and others)
. <<io#io.caching.provider.hazelcast,Hazelcast>>
. <<io#io.caching.provider.couchbase,Couchbase>>
. <<io#io.caching.provider.redis,Redis>>
. <<io#io.caching.provider.caffeine,Caffeine>>
. <<io#io.caching.provider.simple,Simple>>
@@ -116,6 +117,31 @@ If a `HazelcastInstance` has been auto-configured, it is automatically wrapped i
[[io.caching.provider.couchbase]]
==== Couchbase
If Spring Data Couchbase is available and Couchbase is <<data#data.nosql.couchbase,configured>>, a `CouchbaseCacheManager` is auto-configured.
It is possible to create additional caches on startup by setting the configprop:spring.cache.cache-names[] property and cache defaults can be configured by using `spring.cache.couchbase.*` properties.
For instance, the following configuration creates `cache1` and `cache2` caches with an entry _expiration_ of 10 minutes:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
cache-names: "cache1,cache2"
couchbase:
expiration: "10m"
----
If you need more control over the configuration, consider registering a `CouchbaseCacheManagerBuilderCustomizer` bean.
The following example shows a customizer that configures a specific entry expiration for `cache1` and `cache2`:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/io/caching/provider/couchbase/MyCouchbaseCacheManagerConfiguration.java[]
----
[[io.caching.provider.redis]]
==== Redis
If https://redis.io/[Redis] is available and configured, a `RedisCacheManager` is auto-configured.