lime是什么水果| 天蝎座什么星象| 粽子是什么意思| 脚底发红是什么原因| joseph是什么意思| 肠粉为什么叫肠粉| 氯胺酮是什么| 龙的五行属性是什么| 梦到自己拔牙齿是什么预兆| 吃什么对肺结节好| 乙肝复查检查什么项目| 什么样的人容易猝死| 甲功是查什么的| 01年是什么年| 前白蛋白是什么意思| 波推飞机什么意思| 什么情况下才做冠脉cta| 加湿器有什么用| 为什么老打哈欠| 脑委缩吃什么药能空制| 刀子嘴豆腐心是什么意思| 什么是标准差| 央企董事长什么级别| 特殊情况是什么意思| 八段锦是什么| 血液粘稠会有什么症状| 纵隔淋巴结转移是什么意思| 揽子是什么意思| 蛇缠腰是什么病| 银屑病是什么| 弥可保是什么药| 凉粉是什么材料做的| 什么算高危性行为| 芜湖有什么特产| nba什么时候开始| 抗sm抗体阳性什么意思| 伟五行属什么| 感冒嗓子疼吃什么药| 为什么老是打嗝| 吴亦凡属什么| 什么是碧玺| 感冒能吃什么水果| 小孩出汗多是什么原因| 皮肤容易晒黑是什么原因| 什么情况需要割包皮| acca是什么专业| 寻的部首是什么| 甲状腺结节忌口什么| 闭日是什么意思| 墨池为什么不爱柔嘉了| 干冰是什么| 太平公主叫什么名字| 为什么过敏反复发作| 黄芪的读音是什么| 手指甲有竖纹是什么原因| 发烧反反复复是什么原因| 十余年是什么意思| 维生素c什么时候吃效果最好| 吃什么利尿最快| 什么是信念| 浪琴手表什么档次| ts和cd有什么区别| Polo什么意思| 片状低回声区什么意思| 玉米热量高为什么还减肥| 血小板过低有什么危害| 肝脏在什么位置图片| icd医学上是什么意思| 男人硬不起来是什么原因| 长白头发缺什么维生素| 白玫瑰代表什么| 蛋白粉吃多了有什么危害| 盐酸左氧氟沙星片治什么病| 医院挂号用什么app| 北伐是什么意思| 右下腹疼痛挂什么科| 肝功能异常是什么| 肛门疼痛是什么原因引起的| 请节哀是什么意思| 身体不出汗是什么原因| 紫外线是什么意思| 包含是什么意思| 绿本是什么| 芒种可以种什么菜| ng是什么单位| 广东是什么气候| 孕妇胃痛可以吃什么药| 孕酮低吃什么补得快| 福祸相依什么意思| 尔时是什么意思| 男生下面疼是什么原因| 时柱代表什么| 什么是人| 菊花茶喝多了有什么坏处| ex什么意思| 黄体功能不足是什么原因造成的| 右边肋骨疼是什么原因| 什么1| 口腔溃疡吃什么水果好| 老人脚肿是什么征兆| 昆明有什么特产| 四平八稳是什么意思| 画龙点睛什么意思| 生孩子前要注意什么| 什么路最窄打一生肖| 女人腿肿应该检查什么| 胎停是什么原因引起的| 中医学是什么| 入党有什么好处| 用盐刷牙有什么好处和坏处| 为什么肠道总是咕咕的响| 沸去掉三点水念什么| 六月什么星座| 左眼皮跳什么意思| 72年鼠是什么命| 全麦粉是什么面粉| 胃热是什么原因引起的| 南瓜是什么形状| 劳动的反义词是什么| 11点是什么时辰| 洗劫一空是什么意思| 张嘴睡觉有什么危害| 苑什么意思| 七一年属什么生肖| c7是什么意思| 孕育是什么意思| 什么是双规| 六九是什么意思| 妙手回春是什么意思| 印度为什么用手吃饭| 蟑螂屎长什么样| 肺部有问题一般会出现什么症状| 从容面对是什么意思| 马子什么意思| 9月份什么星座| 世事无常什么意思| 哲五行属什么| 狐臭和腋臭有什么区别| 血管瘤是什么引起的| 月经为什么会提前| 电饭锅内胆是什么材质| 嘴角长痘痘是什么原因| 自在是什么意思| 灵芝的功效与作用是什么| 盆腔镜检查是查什么的| xg是什么意思| 孟德是什么意思| 身上长扁平疣是什么原因造成的| 叶黄素对眼睛有什么功效| 上什么环最好最安全伤害小| 海龟是什么动物| 血型o型rh阳性是什么意思| 一个月来两次月经是什么原因| 肺炎可以吃什么水果| 恶作剧是什么意思| 打鼾是什么意思| hpv阳性是什么病| 胃疼做什么检查| 胃老是恶心想吐是什么原因| 乐不思蜀是什么意思| 男士脸黑用什么能美白| 飞机什么时候停止登机| 小美女是什么意思| 异想天开是什么意思| 七星瓢虫吃什么食物| 六一年属什么生肖| 鼠分念什么| 更年期出汗吃什么药| 豚的右边念什么| 老年人睡眠多是什么原因| 肛门口瘙痒涂什么药膏| 喝酒上脸是什么原因| 七月二十九是什么星座| 橡胶过敏是什么症状| 汪是什么意思| 做什么能快速赚钱| 未可以加什么偏旁| 什么细节能感动摩羯男| 严重失眠吃什么药| 心五行属什么| 甲状腺功能亢进是什么意思| 什么一| 白月光是什么意思| 做人流挂什么科| 吃什么容易放屁| 子子念什么| 熊猫血是什么血型| 八婆什么意思| 白开水喝多了有什么危害| 女人体检都查什么项目| 类风湿性关节炎的症状是什么| 什么瓜不能吃脑筋急转弯| 京东自营店什么意思| 脚崴了用什么药| mf是什么意思| 守夜是什么意思| nm是什么意思| 小猫泪痕重什么原因| 虾和什么相克| 利可君片是治什么病| 梦见打碎碗是什么预兆| 萎缩性胃炎用什么药最好| 军统是什么| 海带和什么菜搭配好吃| 脾阳虚吃什么药| 郡字五行属什么| 上升水瓶座为什么可怕| 桃子什么时候成熟| 杨贵妃属什么生肖| 阴道什么形状| 四联用药是些什么药| 梦见刷牙是什么预兆| 7月1号是什么节| 什么生| 局灶肠化是什么意思| 自作多情是什么意思| 胎儿腹围偏大说明什么| 高回声结节是什么意思| 金黄色葡萄球菌是什么| bra是什么| 海豹油有什么功效| 怀孕期间吃什么对胎儿发育好| 为什么男怕属鸡| 圆圆的月亮像什么| 梦见脱发是什么征兆| 无名指戴戒指代表什么| 纵隔是什么意思| 吃鹅蛋有什么好处| 两岁宝宝不开口说话是什么原因| 小儿舌苔白厚什么原因| 孕妇吃辣椒对胎儿有什么影响| 微针是什么| 乙型肝炎e抗体阳性是什么意思| 邓绥和阴丽华什么关系| 疑心病是什么意思| 产复欣颗粒什么时候吃| 吃什么可以降胆固醇| 下岗是什么意思| 胃息肉是什么原因造成的| 稀字五行属什么| 送老师什么花好| dhea是什么| 低钾是什么原因引起的| 什么是网约车| 花生什么时候收| 软化灶是什么意思| 绿豆配什么打豆浆最好| 广州属于什么气候| 吃环孢素有什么副作用| 8月10日是什么星座| 育字五行属什么| Polo什么意思| 土豆与什么食物相克| 除夕是什么意思| fe是什么意思| 发烧反反复复是什么原因| hpv是什么检查| 大陆对什么| 角逐是什么意思| 甲状腺是什么意思| 扁桃体2度是什么意思| 人越来越瘦是什么原因| 牡丹花什么时候开花| 漂脱是什么意思| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Docker Offload: One of the Best Features for AI Workloads
  • KV Caching: The Hidden Speed Boost Behind Real-Time LLMs
  • 5 Popular Standalone JavaScript Spreadsheet Libraries
  • Should You Switch to a Monorepo? A Developer’s No-Fluff Guide
  1. DZone
  2. Coding
  3. Frameworks
  4. First Steps to Using Spring Boot and Cassandra

17日起 开发商和中介要核实外地购房者社保证明

Get started using Spring Boot and the Apache Cassandra NoSQL database.

By 
Biju Kunjummen user avatar
Biju Kunjummen
·
Apr. 25, 16 · Tutorial
Likes (9)
Comment
Save
Tweet
Share
64.1K Views
百度 接下来的关键一步是高层领导认识到合作的潜力:中国已扎根于此,西方和非洲国家都应最大限度地利用中国带来的机遇。

Join the DZone community and get the full member experience.

Join For Free

If you want to start using Cassandra NoSQL database with Spring Boot, the best resource is likely the Cassandra samples available here and the Spring data Cassandra documentation.

Here I will take a little more roundabout way, by actually installing Cassandra locally and running a basic test against it and I aim to develop this sample into a more comprehensive example with the next blog post. 

Setting up a Local Cassandra Instance

Your mileage may vary, but the simplest way to get a local install of Cassandra running is to use the Cassandra cluster manager(ccm) utility, available here.

ccm create test -v 2.2.5 -n 3 -s

Or a more traditional approach may simply be to download it from the Apache site. If you are following along, the version of Cassandra that worked best for me is the 2.2.5 one.

With either of the above, start up Cassandra, using ccm:

ccm start test

or with the download from the Apache site:

bin/cassandra -f

The -f flag will keep the process in the foreground, this way stopping the process will be very easy once you are done with the samples.

Now connect to this Cassandra instance:

bin/cqlsh

and create a sample Cassandra keyspace:

CREATE KEYSPACE IF NOT EXISTS sample WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}

Using Spring Boot Cassandra

Along the lines of anything Spring Boot related, there is a starter available for pulling in all the relevant dependencies of Cassandra, specified as a gradle dependency here:

compile('org.springframework.boot:spring-boot-starter-data-cassandra')

This will pull in the dependencies that trigger the Auto-configuration for Cassandra related instances - a Cassandra session mainly.

For the sample I have defined an entity called the Hotel defined the following way:

package cass.domain;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

import java.io.Serializable;
import java.util.UUID;

@Table("hotels")
public class Hotel implements Serializable {

    private static final long serialVersionUID = 1L;

    @PrimaryKey
    private UUID id;

    private String name;

    private String address;

    private String zip;

    private Integer version;

    public Hotel() {
    }

    public Hotel(String name) {
        this.name = name;
    }

    public UUID getId() {
        return id;
    }

    public String getName() {
        return this.name;
    }

    public String getAddress() {
        return this.address;
    }

    public String getZip() {
        return this.zip;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

}

and the Spring data repository to manage this entity:

import cass.domain.Hotel;
import org.springframework.data.repository.CrudRepository;

import java.util.UUID;

public interface HotelRepository extends CrudRepository<Hotel, UUID>{}

A corresponding cql table is required to hold this entity:

CREATE TABLE IF NOT EXISTS  sample.hotels (
    id UUID,
    name varchar,
    address varchar,
    zip varchar,
    version int,
    primary key((id))
);

That is essentially it, Spring data support for Cassandra would now manage all the CRUD operations of this entity and a test looks like this:

import cass.domain.Hotel;
import cass.repository.HotelRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleCassandraApplication.class)
public class SampleCassandraApplicationTest {

 @Autowired
 private HotelRepository hotelRepository;

 @Test
 public void repositoryCrudOperations() {
  Hotel sample = sampleHotel();
  this.hotelRepository.save(sample);

  Hotel savedHotel = this.hotelRepository.findOne(sample.getId());

  assertThat(savedHotel.getName(), equalTo("Sample Hotel"));

  this.hotelRepository.delete(savedHotel);
 }

 private Hotel sampleHotel() {
  Hotel hotel = new Hotel();
  hotel.setId(UUID.randomUUID());
  hotel.setName("Sample Hotel");
  hotel.setAddress("Sample Address");
  hotel.setZip("8764");
  return hotel;
 }

}

Here is the github repo with this sample. There is not much to this sample yet, in the next blog post I will enhance this sample to account for the fact that it is very important to understand the distribution of data across a cluster in a NoSQL system and how the entity like Hotel here can be modeled for efficient CRUD operations.

Spring Framework Spring Boot

Published at DZone with permission of Biju Kunjummen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

民考民是什么意思 病毒性扁桃体炎吃什么药 淘宝什么时候成立的 男的有霉菌是什么症状 同型半胱氨酸查什么
痔疮吃什么水果 经常喝苏打水有什么好处和坏处 尼特族是什么意思 瘴气是什么 8月28日什么星座
布谷鸟长什么样 备孕需要注意些什么 9.21是什么星座 王羲之兰亭序是什么字体 宝宝什么时候断奶最好
马冬梅是什么梗 油茶是什么 自来水是什么水 一厢情愿是什么意思 什么心什么目
缺金的人戴什么最旺hcv8jop0ns5r.cn 学名是什么意思hcv8jop1ns9r.cn 智齿是什么hcv8jop4ns2r.cn 良心是什么意思hcv8jop0ns9r.cn Polo什么意思jinxinzhichuang.com
什么是化学阉割hcv9jop3ns2r.cn 榴莲什么人不适合吃hkuteam.com 什么桥下没有水脑筋急转弯gysmod.com 什么意思hcv9jop0ns5r.cn 画龙点睛什么意思hcv8jop4ns0r.cn
什么是高脂肪食物hcv9jop4ns4r.cn 免冠是什么意思travellingsim.com 忌行丧是什么意思hcv8jop3ns9r.cn 什么叫传统文化hcv9jop8ns1r.cn 小腿经常抽筋是什么原因hcv8jop0ns2r.cn
适合是什么意思hcv9jop0ns1r.cn 叉烧是什么意思hcv9jop0ns9r.cn 慢性萎缩性胃炎吃什么食物好1949doufunao.com 咳嗽吐黄痰吃什么药hcv8jop0ns4r.cn 边缘性行为包括什么hcv8jop2ns3r.cn
百度