Home > OS >  Spring Boot Astra Cassandra - keyspace specified in application.yml but still throws error "No
Spring Boot Astra Cassandra - keyspace specified in application.yml but still throws error "No

Time:05-27

I am trying to build a very simple api connecting to an astra Cassandra nodal database with spring boot. However, even when I have specified the keyspace in application.yml, it still throws the exception:

com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: No keyspace has been specified. USE a keyspace, or explicitly specify keyspace.tablename

Here is my application.yml:

astra.api:
  application-token: <my-token>
  database-id: <my-db-id>
  database-region: <my-db-region>

astra.cql:
  enabled: true
  downloadScb.path: secure-connect.zip

spring.data.cassandra:
  keyspace-name: shopping_list
  schema-action: CREATE_IF_NOT_EXISTS

I have also tried using keyspace instead of keyspace-name, and putting it under astra.api or even astra.cql. None of these works, though.

I am following this tutorial exactly but I cannot figure out what is the problem.

I have checked the token, database-id and database-region are all correct and the secure connect bundle is also there. The application can indeed get the other values from application.yml such as the scb path and schema-action but apparently not keyspace-name.

Thanks a lot for any input!

CodePudding user response:

The astra-spring-boot-starter (with all key astra.*) will initialize CqlSession and any connection needed for Astra (Cassandra, Rest Apis, gRPC, pulsar...).

Spring Data Casandra detects the connection and uses it. You can use any configuration key of the Cassandra driver below driver-config.

The application.yaml should look like.

astra:
  api:
    application-token: <your_token>
    database-id: <your_db_id>
    database-region: <your_db_region>
  cql:
    enabled: true
    download-scb: 
    enabled: true
    driver-config:
      basic:
        session-keyspace: <your_keyspace>

Documentation of the starter https://github.com/datastax/astra-sdk-java/wiki/Spring-Boot-Starter-Quickstart#4-configuration

Sample working project (mvc, rest, cassandra, Oauth2, thymeleaf) https://github.com/datastaxdevs/workshop-betterreads

  • Related