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
The dependencies for the application are specified in the `build.gradle` file in the source folder. Dependencies can be installed through `gradle` the default package manager for Java.
39
41
40
42
```
41
-
gradle build -x test
43
+
./gradlew build -x test
42
44
```
43
45
44
46
Note: The `-x test` option is used to skip the tests. The tests require the application to be running.
@@ -54,30 +56,47 @@ Specifically, you need to do the following:
54
56
- Create the [database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html) to access the travel-sample bucket (Read and Write) used in the application.
55
57
-[Allow access](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) to the Cluster from the IP on which the application is running.
56
58
57
-
All configuration for communication with the database is read from the environment variables. We have provided a convenience feature in this quickstart to read the environment variables from a local file, `application.properties` in the `src/main/resources` folder.
59
+
All configuration for communication with the database is read from environment variables. This quickstart provides two convenient ways to set up your database connection:
58
60
59
-
You can also set the environment variables directly in your environment such as:
61
+
### Option 1: Environment Variables (Recommended for Production)
62
+
63
+
Set the environment variables directly in your environment:
60
64
61
65
```sh
62
66
export DB_CONN_STR=couchbases://<cluster-url>
63
-
export DB_USERNAME=Administrator
64
-
export DB_PASSWORD=password
67
+
export DB_USERNAME=your-username
68
+
export DB_PASSWORD=your-password
69
+
```
70
+
71
+
### Option 2: .env File (Recommended for Local Development)
72
+
73
+
Create a `.env` file in the project root directory:
74
+
75
+
```env
76
+
# Copy from .env.example and update with your actual values
The `application.properties` file should look like this:
82
+
The `application.properties` file uses these environment variables with modern Spring Boot 3.5+ properties:
68
83
69
84
```properties
85
+
# Server configuration
70
86
server.forward-headers-strategy=framework
71
-
spring.couchbase.bootstrap-hosts=DB_CONN_STR
72
-
spring.couchbase.bucket.name=travel-sample
73
-
spring.couchbase.bucket.user=DB_USERNAME
74
-
spring.couchbase.bucket.password=DB_PASSWORD
75
-
spring.couchbase.scope.name=inventory
76
-
```
77
87
78
-
You can specify the connection string, username, and password using environment variables. The application will read these environment variables and use them to connect to the database.
88
+
# Modern Couchbase configuration (Spring Boot 3.5+)
89
+
spring.couchbase.connection-string=${DB_CONN_STR}
90
+
spring.couchbase.username=${DB_USERNAME}
91
+
spring.couchbase.password=${DB_PASSWORD}
92
+
93
+
# Couchbase connection optimizations
94
+
spring.couchbase.env.timeouts.query=30000ms
95
+
spring.couchbase.env.timeouts.key-value=5000ms
96
+
spring.couchbase.env.timeouts.connect=10000ms
97
+
```
79
98
80
-
Additionally, you can specify the connection string, username, and password directly in the `application.properties` file.
99
+
The application automatically loads environment variables from the `.env` file for local development convenience.
81
100
82
101
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
83
102
@@ -91,17 +110,17 @@ You do not need to make any changes to your configuration for this quickstart. H
// Since bucket auto-configuration is removed in modern Spring Boot, we hardcode the bucket name
123
+
privateString bucketName="travel-sample";
105
124
106
125
@Override
107
126
publicStringgetConnectionString() {
@@ -159,7 +178,8 @@ public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
159
178
160
179
> _from config/CouchbaseConfiguration.java_
161
180
162
-
This default configuration assumes that you have a locally running Couchbae server and use a standard administrative login and password for demonstration purposes.
181
+
This configuration uses modern Spring Boot 3.5+ properties and automatically loads environment variables from `.env` files for local development. The configuration assumes you have either a locally running Couchbase server or a Couchbase Capella cluster.
182
+
163
183
Applications deployed to production or staging environments should use less privileged credentials created using [Role-Based Access Control](https://docs.couchbase.com/go-sdk/current/concept-docs/rbac.html).
164
184
Please refer to [Managing Connections using the Java SDK with Couchbase Server](https://docs.couchbase.com/java-sdk/current/howtos/managing-connections.html) for more information on Capella and local cluster connections.
165
185
@@ -170,13 +190,13 @@ Please refer to [Managing Connections using the Java SDK with Couchbase Server](
170
190
At this point, we have installed the dependencies, loaded the travel-sample data and configured the application with the credentials. The application is now ready and you can run it.
171
191
172
192
```sh
173
-
gradle bootRun
193
+
./gradlew bootRun
174
194
```
175
195
176
-
Note: If you're using Windows, you can run the application using the `gradle.bat` executable.
196
+
Note: If you're using Windows, you can run the application using the Gradle wrapper batch file.
Note: The `application.properties` file has the connection information to connect to your Capella cluster. These will be part of the environment variables in the Docker container.
220
+
Note: Pass your database credentials as environment variables to the Docker container. The `.env` file is used only for local development and won't be available in Docker containers.
197
221
198
222
### Verifying the Application
199
223
@@ -210,9 +234,11 @@ The application will run on port 8080 of your local machine (http://localhost:80
210
234
To run the integration tests, use the following commands:
211
235
212
236
```sh
213
-
gradletest
237
+
./gradlewtest
214
238
```
215
239
240
+
Note: The tests include comprehensive integration tests that connect to your Couchbase cluster and validate all CRUD operations with clean logging output.
0 commit comments