Skip to content

Commit 77fef2e

Browse files
committed
DATACOUCH-518 - Refresh configuration doc section.
This changeset does not add new docs to the config section, but makes sure that the information available is not outdated.
1 parent 7facf6c commit 77fef2e

File tree

1 file changed

+30
-66
lines changed

1 file changed

+30
-66
lines changed

src/main/asciidoc/configuration.adoc

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ As a result, the library can be included like any other maven dependency:
1616
<dependency>
1717
<groupId>org.springframework.data</groupId>
1818
<artifactId>spring-data-couchbase</artifactId>
19-
<version>2.0.0.RELEASE</version>
19+
<version>4.0.0.RELEASE</version>
2020
</dependency>
2121
----
2222
====
@@ -33,7 +33,7 @@ Here is an example on how to use the current SNAPSHOT dependency:
3333
<dependency>
3434
<groupId>org.springframework.data</groupId>
3535
<artifactId>spring-data-couchbase</artifactId>
36-
<version>2.1.0.BUILD-SNAPSHOT</version>
36+
<version>4.0.0.BUILD-SNAPSHOT</version>
3737
</dependency>
3838
3939
<repository>
@@ -45,18 +45,13 @@ Here is an example on how to use the current SNAPSHOT dependency:
4545
====
4646

4747
Once you have all needed dependencies on the classpath, you can start configuring it.
48-
Both Java and XML config are supported.
49-
The next sections describe both approaches in detail.
48+
Only Java config is supported (XML config has been removed in 4.0).
5049

5150
[[configuration-java]]
5251
== Annotation-based Configuration ("JavaConfig")
5352

54-
The annotation based configuration approach is getting more and more popular.
55-
It allows you to get rid of XML configuration and treat configuration as part of your code directly.
5653
To get started, all you need to do is subclcass the `AbstractCouchbaseConfiguration` and implement the abstract methods.
5754

58-
Please make sure to have cglib support in the classpath so that the annotation based configuration works.
59-
6055
.Extending the `AbstractCouchbaseConfiguration`
6156
====
6257
[source,java]
@@ -66,80 +61,49 @@ Please make sure to have cglib support in the classpath so that the annotation b
6661
public class Config extends AbstractCouchbaseConfiguration {
6762
6863
@Override
69-
protected List<String> getBootstrapHosts() {
70-
return Collections.singletonList("127.0.0.1");
64+
public String getConnectionString() {
65+
return "couchbase://127.0.0.1";
66+
}
67+
68+
@Override
69+
public String getUserName() {
70+
return "Administrator";
7171
}
7272
7373
@Override
74-
protected String getBucketName() {
75-
return "beer-sample";
74+
public String getPassword() {
75+
return "password";
7676
}
7777
7878
@Override
79-
protected String getPassword() {
80-
return "";
79+
public String getBucketName() {
80+
return "travel-sample";
8181
}
8282
}
8383
----
8484
====
8585

86-
All you need to provide is a list of Couchbase nodes to bootstrap into (without any ports, just the IP address or hostname).
87-
Please note that while one host is sufficient in development, it is recommended to add 3 to 5 bootstrap nodes here.
88-
Couchbase will pick up all nodes from the cluster automatically, but it could be the case that the only node you've provided is experiencing issues while you are starting the application.
86+
The connection string is made up of a list of hosts and an optional scheme (`couchbase://`) as shown in the code above.
87+
All you need to provide is a list of Couchbase nodes to bootstrap into (separated by a `,`). Please note that while one
88+
host is sufficient in development, it is recommended to add 3 to 5 bootstrap nodes here. Couchbase will pick up all nodes
89+
from the cluster automatically, but it could be the case that the only node you've provided is experiencing issues while
90+
you are starting the application.
8991

90-
The `bucketName` and `password` should be the same as configured in Couchbase Server itself.
91-
In the example given, we are connecting to the `beer-sample` bucket which is one of the sample buckets shipped with Couchbase Server and has no password set by default.
92+
The `userName` and `password` are configured in your Couchbase Server cluster through RBAC (role-based access control).
93+
The `bucketName` reflects the bucket you want to use for this configuration.
9294

93-
Depending on how your environment is set up, the configuration will be automatically picked up by the context or you need to instantiate your own one.
94-
How to manage configurations is not in scope of this manual, please refer to the spring documentation for more information on that topic.
95+
Additionally, the SDK environment can be tuned by overriding the `configureEnvironment` method which takes a
96+
`ClusterEnvironment.Builder` to return a configured `ClusterEnvironment`.
9597

96-
Additionally, the SDK environment can be tuned by overriding the `getEnvironment()` method to return a properly tuned `CouchbaseEnvironment`.
97-
98-
While not immediately obvious, much more things can be customized and overridden as custom beans from this configuration (for example repositories, query consistency, validation and custom converters).
98+
Many more things can be customized and overridden as custom beans from this configuration (for example repositories,
99+
validation and custom converters).
99100

100101
TIP: If you use `SyncGateway` and `CouchbaseMobile`, you may run into problem with fields prefixed by `_`.
101102
Since Spring Data Couchbase by default stores the type information as a `_class` attribute this can be problematic.
102-
Override `typeKey()` (for example to return `MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE`) to change the name of said attribute.
103-
104-
TIP: For generated queries, if you want strong consistency (at the expense of performance), you can override `getDefaultConsistency()` and return `Consistency.READ_YOUR_OWN_WRITES`.
105-
106-
[[configuration-xml]]
107-
== XML-based Configuration
108-
109-
The library provides a custom namespace that you can use in your XML configuration:
110-
111-
.Basic XML configuration
112-
====
113-
[source,xml]
114-
----
115-
<?xml version="1.0" encoding="UTF-8"?>
116-
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
117-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
118-
xmlns="http://www.springframework.org/schema/data/couchbase
119-
xsi:schemaLocation="http://www.springframework.org/schema/beans
120-
https://www.springframework.org/schema/beans/spring-beans.xsd
121-
http://www.springframework.org/schema/data/couchbase
122-
https://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd">
123-
124-
<couchbase:cluster>
125-
<couchbase:node>127.0.0.1</couchbase:node>
126-
</couchbase:cluster>
127-
128-
<!-- This is needed to probe the server for N1QL support -->
129-
<!-- Can be either cluster credentials or a bucket credentials -->
130-
<couchbase:clusterInfo login="beer-sample" password=""/>
131-
132-
<couchbase:bucket bucketName="beer-sample" bucketPassword=""/>
133-
</beans:beans>
134-
----
135-
====
136-
137-
This code is equivalent to the java configuration approach shown above.
138-
You can customize the SDK `CouchbaseEnvironment` via the `<couchbase:env/>` tag, that supports most tuning parameters as attributes.
139-
It is also possible to configure templates and repositories, which is shown in the appropriate sections.
140-
141-
IMPORTANT: The XML configuration **must** include the `clusterInfo` credentials, in order to be able to detect N1QL feature.
103+
Override `typeKey()` (for example to return `MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE`) to change the
104+
name of said attribute.
142105

143-
If you start your application, you should see Couchbase INFO level logging in the logs, indicating that the underlying Couchbase Java SDK is connecting to the database.
144-
If any errors are reported, make sure that the given credentials and host information are correct.
106+
If you start your application, you should see Couchbase INFO level logging in the logs, indicating that the underlying
107+
Couchbase Java SDK is connecting to the database. If any errors are reported, make sure that the given credentials
108+
and host information are correct.
145109

0 commit comments

Comments
 (0)