0
我正在使用Spring-Data-Cassandra 1.2.2。我正在使用XML配置如下。我读了默认的ConsistencyLevel是ONE,我想将它设置为QUORUM。我如何在XML中配置它? 如果需要,我可以升级我的Spring-Data-Cassandra版本。如何设置Spring Data中的一致性级别Cassandra XML config
<?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'。从Cassandra 1.5的Spring Data开始,'QueryOptions'的设置可以在'CassandraCqlClusterFactoryBean'上找到,但是它不能通过XML配置获得。 – mp911de
@ mp911de - 感谢您的评论!我的Q没有答案,似乎JavaConfig是唯一的解决方案。从1.2.2升级到1.5被证明在我的proj中其他spring-data(mongo&JPA)依赖关系有点复杂,所以我使用了'com.datastax.driver.core.Cluster.builder()。withQueryOptions新的QueryOptions()。setConsistencyLevel(ConsistencyLevel.QUORUM))'' –