【发布时间】:2017-08-07 17:38:23
【问题描述】:
我正在使用 Spring-Data-Cassandra 1.2.2。我正在使用如下 XML 配置。我读到默认的 ConsistencyLevel 是 ONE,我想将其设置为 QUORUM。如何在 XML 中配置它? 如果需要,我可以升级我的 Spring-Data-Cassandra 版本。
<?xml version='1.0'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cassandra="http://www.springframework.org/schema/data/cassandra"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/cql http://www.springframework.org/schema/cql/spring-cql.xsd
http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Loads the properties into the Spring Context and uses them to fill in placeholders in the bean definitions -->
<context:property-placeholder location="classpath:resources.properties" />
<!-- REQUIRED: The Cassandra Cluster -->
<cassandra:cluster contact-points="${cassandra.contactpoints}" port="${cassandra.port}" />
<!-- REQUIRED: The Cassandra Session, built from the Cluster, and attaching to a keyspace -->
<cassandra:session keyspace-name="${cassandra.keyspace}" schema-action="CREATE" />
<!-- REQUIRED: The Default Cassandra Mapping Context used by CassandraConverter -->
<cassandra:mapping />
<!-- REQUIRED: The Default Cassandra Converter used by CassandraTemplate -->
<cassandra:converter />
<!-- REQUIRED: The Cassandra Template is the building block of all Spring Data Cassandra -->
<cassandra:template />
<!-- OPTIONAL: If you are using Spring Data Cassandra Repositories, add your base packages to scan here -->
<cassandra:repositories base-package="com.my.package.cassandrarepository" />
</beans>
【问题讨论】:
-
自己创建
Cluster。自 Spring Data for Apache Cassandra 1.5 起,QueryOptions的设置可在CassandraCqlClusterFactoryBean上使用,但无法通过 XML 配置使用。 -
@mp911de - 感谢您的评论!我的 Q 没有答案,似乎 JavaConfig 是唯一的解决方案。从 1.2.2 升级到 1.5 被证明是我项目中其他 spring-data(mongo & JPA) 依赖项的复杂性,所以我使用了
com.datastax.driver.core.Cluster.builder().withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))
标签: cassandra datastax-java-driver spring-data-cassandra