Skip to content

Commit 4cad947

Browse files
committed
updated readme
1 parent 181de8b commit 4cad947

File tree

1 file changed

+54
-28
lines changed

1 file changed

+54
-28
lines changed

README.md

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ To run this prebuilt project, you will need:
1818
- [Couchbase Capella](https://www.couchbase.com/products/capella/) cluster with [travel-sample](https://docs.couchbase.com/java-sdk/current/ref/travel-app-data-model.html) bucket loaded.
1919
- To run this tutorial using a self-managed Couchbase cluster, please refer to the [appendix](#running-self-managed-couchbase-cluster).
2020
- [Java 17 or higher](https://www.oracle.com/in/java/technologies/downloads/#java17)
21-
- Ensure that the Java version is compatible with the Couchbase SDK.
21+
- **Java 17+ is required** for Gradle 9.0+ compatibility
22+
- Ensure that the Java version is compatible with the Couchbase SDK
2223
- [Loading Travel Sample Bucket](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html#import-sample-data)
2324
- If `travel-sample` is not loaded in your Capella cluster, you can load it by following the instructions for your Capella Cluster
24-
- [Gradle 8.6 or higher](https://gradle.org/releases/)
25+
- [Gradle 9.0 or higher](https://gradle.org/releases/)
26+
- The project uses Gradle wrapper, so manual installation is optional
2527

2628
## App Setup
2729

@@ -38,7 +40,7 @@ git clone https://github.com/couchbase-examples/java-springdata-quickstart.git
3840
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.
3941

4042
```
41-
gradle build -x test
43+
./gradlew build -x test
4244
```
4345

4446
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:
5456
- 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.
5557
- [Allow access](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) to the Cluster from the IP on which the application is running.
5658

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:
5860

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:
6064

6165
```sh
6266
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
77+
DB_CONN_STR=couchbases://your-cluster-url.cloud.couchbase.com
78+
DB_USERNAME=your-username
79+
DB_PASSWORD=your-password
6580
```
6681

67-
The `application.properties` file should look like this:
82+
The `application.properties` file uses these environment variables with modern Spring Boot 3.5+ properties:
6883

6984
```properties
85+
# Server configuration
7086
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-
```
7787

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+
```
7998

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.
81100

82101
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
83102
@@ -91,17 +110,17 @@ You do not need to make any changes to your configuration for this quickstart. H
91110
@EnableCouchbaseRepositories
92111
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
93112

94-
@Value("#{systemEnvironment['DB_CONN_STR'] ?: '${spring.couchbase.bootstrap-hosts:localhost}'}")
113+
@Value("#{systemEnvironment['DB_CONN_STR'] ?: '${spring.couchbase.connection-string:localhost}'}")
95114
private String host;
96115

97-
@Value("#{systemEnvironment['DB_USERNAME'] ?: '${spring.couchbase.bucket.user:Administrator}'}")
116+
@Value("#{systemEnvironment['DB_USERNAME'] ?: '${spring.couchbase.username:Administrator}'}")
98117
private String username;
99118

100-
@Value("#{systemEnvironment['DB_PASSWORD'] ?: '${spring.couchbase.bucket.password:password}'}")
119+
@Value("#{systemEnvironment['DB_PASSWORD'] ?: '${spring.couchbase.password:password}'}")
101120
private String password;
102121

103-
@Value("${spring.couchbase.bucket.name:travel-sample}")
104-
private String bucketName;
122+
// Since bucket auto-configuration is removed in modern Spring Boot, we hardcode the bucket name
123+
private String bucketName = "travel-sample";
105124

106125
@Override
107126
public String getConnectionString() {
@@ -159,7 +178,8 @@ public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
159178

160179
> _from config/CouchbaseConfiguration.java_
161180
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+
163183
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).
164184
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.
165185

@@ -170,13 +190,13 @@ Please refer to [Managing Connections using the Java SDK with Couchbase Server](
170190
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.
171191

172192
```sh
173-
gradle bootRun
193+
./gradlew bootRun
174194
```
175195

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.
177197

178198
```sh
179-
./gradew.bat bootRun
199+
./gradlew.bat bootRun
180200
```
181201

182202
### Using Docker
@@ -190,10 +210,14 @@ docker build -t java-springdata-quickstart .
190210
Run the Docker image
191211

192212
```sh
193-
docker run -d --name springdata-container -p 8080:8080 java-springdata-quickstart
213+
docker run -d --name springdata-container -p 8080:8080 \
214+
-e DB_CONN_STR=couchbases://your-cluster-url.cloud.couchbase.com \
215+
-e DB_USERNAME=your-username \
216+
-e DB_PASSWORD=your-password \
217+
java-springdata-quickstart
194218
```
195219

196-
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.
197221

198222
### Verifying the Application
199223

@@ -210,9 +234,11 @@ The application will run on port 8080 of your local machine (http://localhost:80
210234
To run the integration tests, use the following commands:
211235

212236
```sh
213-
gradle test
237+
./gradlew test
214238
```
215239

240+
Note: The tests include comprehensive integration tests that connect to your Couchbase cluster and validate all CRUD operations with clean logging output.
241+
216242
## Appendix
217243

218244
### Data Model

0 commit comments

Comments
 (0)