[go: nahoru, domu]

Skip to content

iamvickyav/spring-boot-with-cassandra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot with Cassandra

Running Cassandra in Local

To Install Cassandra in Mac

brew install Cassandra

To Start Cassandra

cassandra -f

To access Cassandra from Terminal

cqlsh

Getting Started with Cassandra

Creating Keyspace

CREATE KEYSPACE Sample WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};

use Sample;

Creating Cassandra Table

CREATE TABLE Student(
    id int,
    name text,
    dept text,
    year_of_joining int,
    PRIMARY KEY (id)
);

CREATE TABLE Staff (
    id int, 
    name text,
    dept text,
    subjects list<text>, 
    PRIMARY KEY (id, dept)
);

Inserting sample data in Table

INSERT INTO Student (id, name, dept, year_of_joining) 
VALUES (1, 'Vicky', 'CSE', 2010);

INSERT INTO Staff (id, name, dept, subjects) 
VALUES (1, 'Selvam', 'CSE', ['Compiler Design', 'Operating System']);

Ok, now the DB is ready..! Lets start building the Spring Boot part

Go to https://start.spring.io & choose dependecies web, cassandra. Note: Don't chose JPA dependency when you use Cassandra.

In application.properties, give the keyspace name.

spring.data.cassandra.keyspace-name=Sample

Create your own Repo interface extending CassandraRepository

interface StudentRepo extends CassandraRepository<Student, Integer> {
}

About

Simple Spring Boot Application with Cassandra DB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages