简体   繁体   中英

How to set Consistency Level in Spring Data Cassandra XML config

I am using Spring-Data-Cassandra 1.2.2. I am using XML config as below. I read that the default ConsistencyLevel is ONE, I want to set it to QUORUM. How do I configure it in the XML? I can upgrade my Spring-Data-Cassandra version if required.

<?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>

Seems JavaConfig is the only solution. Upgrading from 1.2.2 to 1.5 was proving to be a bit complicated cos of other spring-data(mongo & JPA) dependencies in my proj. So I used the following config in 1.2.2 version: com.datastax.driver.core.Cluster.builder().withQueryOptions(‌​new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM