You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/configuration.adoc
+30-66Lines changed: 30 additions & 66 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ As a result, the library can be included like any other maven dependency:
16
16
<dependency>
17
17
<groupId>org.springframework.data</groupId>
18
18
<artifactId>spring-data-couchbase</artifactId>
19
-
<version>2.0.0.RELEASE</version>
19
+
<version>4.0.0.RELEASE</version>
20
20
</dependency>
21
21
----
22
22
====
@@ -33,7 +33,7 @@ Here is an example on how to use the current SNAPSHOT dependency:
33
33
<dependency>
34
34
<groupId>org.springframework.data</groupId>
35
35
<artifactId>spring-data-couchbase</artifactId>
36
-
<version>2.1.0.BUILD-SNAPSHOT</version>
36
+
<version>4.0.0.BUILD-SNAPSHOT</version>
37
37
</dependency>
38
38
39
39
<repository>
@@ -45,18 +45,13 @@ Here is an example on how to use the current SNAPSHOT dependency:
45
45
====
46
46
47
47
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).
50
49
51
50
[[configuration-java]]
52
51
== Annotation-based Configuration ("JavaConfig")
53
52
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.
56
53
To get started, all you need to do is subclcass the `AbstractCouchbaseConfiguration` and implement the abstract methods.
57
54
58
-
Please make sure to have cglib support in the classpath so that the annotation based configuration works.
59
-
60
55
.Extending the `AbstractCouchbaseConfiguration`
61
56
====
62
57
[source,java]
@@ -66,80 +61,49 @@ Please make sure to have cglib support in the classpath so that the annotation b
66
61
public class Config extends AbstractCouchbaseConfiguration {
67
62
68
63
@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";
71
71
}
72
72
73
73
@Override
74
-
protected String getBucketName() {
75
-
return "beer-sample";
74
+
public String getPassword() {
75
+
return "password";
76
76
}
77
77
78
78
@Override
79
-
protected String getPassword() {
80
-
return "";
79
+
public String getBucketName() {
80
+
return "travel-sample";
81
81
}
82
82
}
83
83
----
84
84
====
85
85
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.
89
91
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.
92
94
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`.
95
97
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).
99
100
100
101
TIP: If you use `SyncGateway` and `CouchbaseMobile`, you may run into problem with fields prefixed by `_`.
101
102
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:
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.
142
105
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
0 commit comments