Separate Couchbase setup from Spring Data

This commit separates the basic setup of Couchbase from Spring Data so
that a `Bucket` and `Cluster` bucket beans are exposed even if Spring
Data is not available.

A basic setup happens if `spring.couchbase.bootstrap-hosts` is specified,
configuring the `default` bucket with no authentication unless specified
otherwise.

If Spring Data is available, those beans are re-used by default to
configure the `CouchbaseTemplate` and other repository-related beans.

Closes gh-5347
This commit is contained in:
Stephane Nicoll
2016-03-07 13:02:43 +01:00
parent 5fa752a37b
commit e67f2e2983
20 changed files with 835 additions and 258 deletions

View File

@@ -473,6 +473,11 @@ content into your application; rather pick only the properties that you need.
liquibase.url= # JDBC url of the database to migrate. If not set, the primary configured data source is used.
liquibase.user= # Login user of the database to migrate.
# COUCHBASE ({sc-spring-boot-autoconfigure}/couchbase/CouchbaseProperties.{sc-ext}[CouchbaseProperties])
spring.couchbase.bootstrap-hosts= # Couchbase nodes (host or IP address) to bootstrap from.
spring.couchbase.bucket.name=default # Name of the bucket to connect to.
spring.couchbase.bucket.password= # Password of the bucket.
# DAO ({sc-spring-boot-autoconfigure}/dao/PersistenceExceptionTranslationAutoConfiguration.{sc-ext}[PersistenceExceptionTranslationAutoConfiguration])
spring.dao.exceptiontranslation.enabled=true # Enable the PersistenceExceptionTranslationPostProcessor.
@@ -494,11 +499,8 @@ content into your application; rather pick only the properties that you need.
spring.data.cassandra.ssl=false # Enable SSL support.
spring.data.cassandra.username= # Login user of the server.
# COUCHBASE ({sc-spring-boot-autoconfigure}/couchbase/CouchbaseProperties.{sc-ext}[CouchbaseProperties])
# DATA COUCHBASE ({sc-spring-boot-autoconfigure}/data/couchbase/CouchbaseDataProperties.{sc-ext}[CouchbaseDataProperties])
spring.data.couchbase.auto-index=false # Automatically create views and indexes.
spring.data.couchbase.bootstrap-hosts=localhost # Couchbase nodes (host or IP address) to bootstrap from.
spring.data.couchbase.bucket.name= # Name of the bucket to connect to.
spring.data.couchbase.bucket.password= # Password of the bucket.
spring.data.couchbase.consistency=read-your-own-writes # Consistency to apply by default on generated queries.
spring.data.couchbase.repositories.enabled=true # Enable Couchbase repositories.

View File

@@ -3198,25 +3198,39 @@ dependencies in a convenient way.
[[boot-features-connecting-to-couchbase]]
==== Connecting to Couchbase
You can inject an auto-configured `CouchbaseTemplate` instance as you would with any
other Spring Bean. The `spring.data.couchbase.*` properties can be used to customize the
You can very easily get a a `Bucket` and `Cluster` by adding the couchbase SDK and some
configuration. The `spring.couchbase.*` properties can be used to customize the
connection. Generally you will provide the bootstrap hosts, bucket name and password:
[source,properties,indent=0]
----
spring.data.couchbase.bootstrap-hosts=my-host-1,192.168.1.123
spring.data.couchbase.bucket.name=my-bucket
spring.data.couchbase.bucket.password=secret
spring.couchbase.bootstrap-hosts=my-host-1,192.168.1.123
spring.couchbase.bucket.name=my-bucket
spring.couchbase.bucket.password=secret
----
[TIP]
====
You need to provide _at least_ the bucket name, in which case the bootstrap host is
localhost and the password is an empty String. Alternatively, you can define your
own `org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration` `@Bean`
configuration to take control over the whole configuration.
You need to provide _at least_ the bootstrap host(s), in which case the bucket name
is `default` and the password is the empty String. Alternatively, you can define your
own `org.springframework.data.couchbase.config.CouchbaseConfigurer` `@Bean` to take
control over the whole configuration.
====
[[boot-features-spring-data-couchbase-repositories]]
==== Spring Data Couchbase repositories
Spring Data includes repository support for Couchbase. For complete details of Spring
Data Couchbase, refer to their
http://docs.spring.io/spring-data/couchbase/docs/current/reference/html/[reference documentation].
You can inject an auto-configured `CouchbaseTemplate` instance as you would with any
other Spring Bean as long as a _default_ `CouchbaseConfigurer` is available (that
happens when you enable the couchbase support as explained above). If you want to
bypass the auto-configuration for Spring Data Couchbase, provide your own
`org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration`
implementation.
[source,java,indent=0]
----
@Component
@@ -3238,14 +3252,6 @@ If you add a `@Bean` of your own of type `CouchbaseTemplate` named `couchbaseTem
will replace the default.
[[boot-features-spring-data-couchbase-repositories]]
==== Spring Data Couchbase repositories
Spring Data includes repository support for Couchbase. For complete details of Spring
Data Couchbase, refer to their
http://docs.spring.io/spring-data/couchbase/docs/current/reference/html/[reference documentation].
[[boot-features-caching]]
== Caching
The Spring Framework provides support for transparently adding caching to an application.