I'm working on a Spring Boot application that integrates with DataStax Astra DB using the Astra secure bundle. However, I’m encountering persistent issues when trying to establish a connection to the database, and I've been troubleshooting this problem for over 20 hours. Despite following several suggestions and steps to resolve the issue, I'm still getting a ConnectionInitException.
I've been able to connect to Cassandra directly using Python, so I'm confident that my secure bundle is properly configured.
Environment
- Java Version: Java 22 (also downgraded to Java 17 and the exact same error occurred)
- Spring Boot Version: 3.2.5
- Maven: Latest version
- Spring Data Cassandra: Using spring-boot-starter-data-cassandra
- Astra DB Secure Bundle: Specified in the application.yaml file
The Issue When I run the Spring Boot application using mvn spring-boot:run, I receive the following error in the logs:
Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=58cd994e): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)] This error indicates that the application cannot connect to the database, even though I have confirmed that the secure bundle and application token are correctly referenced.
What I've Tried and Verified
- Java Version: I’m using Java 22. I was initially advised to try downgrading to Java 17, as it is more commonly supported in Spring applications. However, switching to Java 17 might cause other problems across my system, so I haven't explored this option yet.
- Secure Bundle: The secure connect bundle is placed in the correct directory, as specified in the application.yaml:
- Port: 29042: I tried setting the port in my application.yaml file to port 29042 after seeing a somewhat related StackOverflow post and solution. Didn't work.
astra: secure-connect-bundle: /path/to/secure-connect-database.zip application-token: AstraCS:<masked_token> keyspace: default_keyspace The bundle is located at src/main/resources/secure-connect-database.zip
Network and Port: I've checked that my network allows connectivity to Astra DB. When specifying port 29042 using telnet, I was able to establish a connection, which ruled out network-level issues. However, hardcoding the port in the Spring Boot configuration did not resolve the issue.
Environment Variables: I confirmed that the environment variables such as
ASTRA_DB_ID,ASTRA_DB_REGION,ASTRA_DB_APPLICATION_TOKEN, and others work because I was able to connect to the database successfully using Python. Here is a snippet from my.envfile:
ASTRA_DB_ID=<masked_db_id> ASTRA_DB_REGION=<masked_region> ASTRA_DB_KEYSPACE=default_keyspace ASTRA_DB_APPLICATION_TOKEN=AstraCS:<masked_token> ASTRA_DB_SECURE_CONNECT_BUNDLE_PATH=/path/to/secure-connect-database.zip Telnet Verification: I've verified connectivity using telnet and was able to connect to the Astra DB on port
29042. This indicates the network path is open and the issue may lie within the Spring Boot application configuration.Updated Dependencies: I updated the Maven
pom.xmlfile to ensure I’m using the correct versions of dependencies for Spring Boot, the Cassandra driver, and other related libraries.
Errors in Detail The error log shows a failure in the CassandraDataAutoConfiguration class when attempting to instantiate a CqlSession. Here is a snippet from the error log:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception with message: Could not reach any contact point, make sure you've provided valid addresses. application.yaml Here’s the relevant portion of the application.yaml file:
astra: secure-connect-bundle: /path/to/secure-connect-database.zip application-token: AstraCS:<masked_token> keyspace: default_keyspace pom.xml Here’s the current configuration in my pom.xml:
<properties> <java.version>22</java.version> </properties> <dependencies> <!-- Spring Boot Starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- Spring Boot Starter Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Boot Starter Data Cassandra --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId> </dependency> <!-- DataStax Java Driver Core --> <dependency> <groupId>com.datastax.oss</groupId> <artifactId>java-driver-core</artifactId> <version>4.14.1</version> </dependency> </dependencies> Additional Notes
- Specifying Port: I tried hardcoding the port 29042 in various configurations, but it didn't seem to help resolve the issue. Initially, it seemed like specifying the port resolved some network issues, but the connection error persists.
- Other Context: I have previously been able to connect to Astra DB using the same credentials and secure bundle with Python, which confirms that the credentials and database setup are correct.
Request for Help I'm looking for any suggestions on how to properly configure the connection between Spring Boot and Astra DB. Could the issue be related to my Java version (Java 22), or is there something else I might be missing in my configuration?
Any insights into what might be causing the ConnectionInitException or suggestions for further troubleshooting would be greatly appreciated. Thank you.
I tried mvn clean install and then mvn spring-boot:run expecting that a connection to the Cassandra database would be established.