微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Boot2的Cassandra怎么连接

这篇文章主要介绍“Spring Boot2的Cassandra怎么连接”,在日常操作中,相信很多人在Spring Boot2的Cassandra怎么连接问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Spring Boot2的Cassandra怎么连接”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

Cassandra

Cassandra是一个开源,分布式数据库管理系统,设计用于处理跨很多商品服务器的大数据。Spring Boot为Cassandra提供自动配置,Spring Data Cassandra提供在它之上的抽象,还有收集依赖的spring-boot-starter-data-cassandra‘Starter’。

连接Cassandra

你可以注入一个自动配置的Cassandratemplate或Cassandra Session实例,就像注入其他Spring Bean那样。spring.data.cassandra.*属性可用来自定义该连接,通常你需要提供keyspace-name和contact-points属性

1spring.data.cassandra.keyspace-name=mykeyspace
2spring.data.cassandra.contact-points=cassandrahost1,cassandrahost2
1@Component
2public class MyBean {
3    private Cassandratemplate template;
4    @Autowired
5    public MyBean(Cassandratemplate template) {
6        this.template = template;
7    }
8    // ...
9}

如果添加自己的Cassandratemplate类型的@Bean,它将替换认实例。

Spring Data Cassandra仓库

Spring Data包含的仓库对Cassandra提供基本支持,目前受到的限制比先前讨论的JPA仓库要多,并且需要使用@Query注解相应的查找方法

到此,关于“Spring Boot2的Cassandra怎么连接”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程之家网站,小编会继续努力为大家带来更多实用的文章

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐