50 minutes, Intermediate, Start Building
This provides an example REST backend built in Java using Spring Boot
for use with the Getting Started with Astra UI.
- How to connect to Astra via the Secure Connect Bundle
- How to manage a Cassandra Session within a JAVA web application
This is an example of a Spring Boot Microservice for use with the Astra Getting Started UI which is found here.
To build and play with this app, follow the build instructions that are located here: https://github.com/DataStax-Examples/getting-started-with-astra-java
Let's do some initial setup.
-
Create a DataStax Astra account if you don't already have one:
-
Define a database name, keyspace name and credentials (Take note of the DB Password)
-
Your Astra DB will be ready when the status will change from
Pending
toActive
💥💥💥 -
Locate the combo
Organization: <Your email>
on the top navigation. In the drop down menu, click your current organization. -
Scroll down to the bottom of the page and locate
Service Account
inSecurity Settings
and selectCopy Credentials
as shown below.
-
Click
Use this template
at the top of the GitHub Repository: -
Enter a repository name and click 'Create repository from template':
Make sure you've completed the prerequisites before starting this step
Make sure that you have:
- Java 11+
- An Astra compatible Java driver, instructions may be found here to install this locally.
- An Astra database with the CQL schema located in schema.cql already added.
- The username, password, keyspace name, and secure connect bundle downloaded from your Astra Database. For information on how to obtain these credentials please read the documentation found here.
This application is a Spring Boot web application. This sample can be run from the root directory using:
cd getting-started-with-astra-java
mvn spring-boot:run
This will startup the application running on http://localhost:8080
You will know that you are up and working when you get the following in your terminal window:
16:23:01.569 INFO com.datastax.astra.GettingStartedWithAstra : Started GettingStartedWithAstra in 1.851 seconds (JVM running for 2.39)
Note: If you want to change the listening port of the application, locate the file src/main/resources/application.yml
and change key server.port
To setup the UI to connect to Java backend define a .env
file in the getting-started-with-astra-ui
project main directory. Inside the file it should have one entry pointing to this project's API endpoint:
BASE_ADDRESS=http://localhost:8080/api
Once you start that project with a npm run build
it will point the UI to the backend API which will then be using Astra as a database. When you first connect to the UI, a dialog box will open asking for Astra connection information.