如何在 Spring Data Cassandra XML 配置中设置一致性级别
How to set Consistency Level in Spring Data Cassandra XML config
我正在使用 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>
似乎 JavaConfig 是唯一的解决方案。事实证明,从 1.2.2 升级到 1.5 有点复杂,因为我项目中的其他 spring-data(mongo & JPA) 依赖项。所以我在 1.2.2 版本中使用了以下配置:com.datastax.driver.core.Cluster.builder().withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))
我正在使用 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>
似乎 JavaConfig 是唯一的解决方案。事实证明,从 1.2.2 升级到 1.5 有点复杂,因为我项目中的其他 spring-data(mongo & JPA) 依赖项。所以我在 1.2.2 版本中使用了以下配置:com.datastax.driver.core.Cluster.builder().withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))