我使用spring boot application.yml 和自动配置功能配置了spring data cassandra客户端。
它对我有用,但是仅当我不使用spring.data.reconnection-policy属性时。 当我使用其中的任何一个( com.datastax.driver.core.policies.ConstantReconnectionPolicy 或 com.datastax.driver.core.policies.ExponentialReconnectionPolicy )时,我都会遇到此错误启动:
原因:org.springframework.beans.BeanInstantiationException:无法实例化[com.datastax.driver.core.policies.ConstantReconnectionPolicy]:未找到默认构造函数;嵌套异常为java.lang.NoSuchMethodException:com.datastax.driver.core.policies.ConstantReconnectionPolicy。() 在org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:127)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.boot.context.properties.PropertyMapper $ Source.lambda $ as $ 2(PropertyMapper.java:207)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] 在org.springframework.boot.context.properties.PropertyMapper $ Source.to(PropertyMapper.java:302)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] 在org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration.cassandraCluster(CassandraAutoConfiguration.java:77)〜[spring-boot-autoconfigure-2.0.3.RELEASE.jar:2.0.3.RELEASE] 在org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration $$ EnhancerBySpringCGLIB $$ 2f475e40.CGLIB $ cassandraCluster $ 0()〜[spring-boot-autoconfigure-2.0.3.RELEASE.jar:2.0.3.RELEASE]
我扩展了策略类,并在其中添加了默认构造函数。在application.yml中包含新类,一切正常。是否可以在没有解决方法的情况下配置重新连接策略,或者这是一个错误?
谢谢。
这是我的application.yml:
春天: 数据: 卡桑德拉: #Cassandra集群的名称。 cluster-name:“测试集群”
# Cluster node addresses.
contact-points: 10.247.198.137
# Login user of the server.
username: cassandra
# Login password of the server.
password: cassandra
# Compression supported by the Cassandra binary protocol.
compression: none
# Port of the Cassandra server.
port: 9042
# Socket option: connection time out.
connect-timeout: 5000ms
# Queries consistency level.
consistency-level: three
# Queries default fetch size.
fetch-size: 5000
# Keyspace name to use.
keyspace-name: testkeyspace
# Enable SSL support.
ssl: true
# Class name of the load balancing policy.
load-balancing-policy: com.datastax.driver.core.policies.RoundRobinPolicy
# Reconnection policy class.
reconnection-policy: com.datastax.driver.core.policies.ConstantReconnectionPolicy
# Class name of the retry policy.
retry-policy: com.datastax.driver.core.policies.DefaultRetryPolicy
# Heartbeat interval after which a message is sent on an idle connection to make sure it's still alive. If a duration suffix is not specified, seconds will be used.
pool.heartbeat-interval: 30s
# Idle timeout before an idle connection is removed. If a duration suffix is not specified, seconds will be used.
pool.idle-timeout: 120s
# Maximum number of requests that get queued if no connection is available.
pool.max-queue-size: 256
# Pool timeout when trying to acquire a connection from a host's pool.
pool.pool-timeout: 5000ms
# Socket option: read time out.
read-timeout: 5000ms
# Type of Cassandra repositories to enable.
repositories.type: auto
# Queries serial consistency level.
serial-consistency-level: three
# Schema action to take at startup.
schema-action: RECREATE_DROP_UNUSED