当启动我的应用程序时,键空间总是被创建,可能在PT2S错误消息之前创建一个或两个表。不知何故,spring.data.cassandra.request.timeout属性没有被接受,或者可能是我的配置有问题?“DriverConfigLoaderBuilderCustomizer”bean没有任何区别。
pom.xml
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR9</version>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<spring.framework.version>5.3.1</spring.framework.version>
application.yml
spring:
data:
cassandra:
port: 9042
keyspace-name: abc
contact-points: localhost
local-datacenter: datacenter1
replication-factor: 1
request:
timeout: 15s
connection:
init-query-timeout: 15s
CassandraConfig.java
@Configuration
@EnableReactiveCassandraRepositories(basePackages = "a.b.c.repository")
public class CassandraConfig extends AbstractReactiveCassandraConfiguration {
@Value("${spring.data.cassandra.contactpoints}")
.
.
@Override
protected String getKeyspaceName() {
return keyspace;
}
@Override protected String getContactPoints() {
return contactPoints;
}
@Override protected int getPort() {
return port;
}
@Override
protected String getLocalDataCenter() {
return datacenter;
}
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.NONE;
}
@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
return Collections.singletonList(CreateKeyspaceSpecification.createKeyspace(getKeyspaceName())
.ifNotExists()
.with(KeyspaceOption.DURABLE_WRITES, true)
.withNetworkReplication(DataCenterReplication.of(getLocalDataCenter(), getReplicationFactor())));
}
@Override
protected KeyspacePopulator keyspacePopulator() {
ResourceKeyspacePopulator keyspacePopulate = new ResourceKeyspacePopulator();
keyspacePopulate.addScript(new ClassPathResource("table-schema.cql"));
return keyspacePopulate;
}
private long getReplicationFactor() {
return replicationFactor;
}
//@Bean
//public DriverConfigLoaderBuilderCustomizer driverConfigLoaderBuilderCustomizer() {
//return loaderBuilder -> loaderBuilder
//.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(15))
//.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(15));
//}
}
修剪错误日志
BeanCreationException: Error creating bean with name 'cassandraSessionFactory'
Invocation of init method failed; nested exception is ScriptStatementFailedException: Failed to execute CQL script statement #2 of class path resource [table-schema.cql]: CREATE TABLE IF NOT EXISTS mytable...
Caused by: org.springframework.data.cassandra.core.cql.session.init.ScriptStatementFailedException: Failed to execute CQL script statement #2 of class path resource [table-schema.cql]: CREATE TABLE IF NOT EXISTS mytanble... nested exception is com.datastax.oss.driver.api.core.DriverTimeoutException: Query timed out after PT2S
at org.springframework.data.cassandra.core.cql.session.init.ScriptUtils.executeCqlScript(ScriptUtils.java:555) ~[spring-data-cassandra-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.cassandra.core.cql.session.init.ResourceKeyspacePopulator.populate
Caused by: com.datastax.oss.driver.api.core.DriverTimeoutException: Query timed out after PT2S
at com.datastax.oss.driver.api.core.DriverTimeoutException.copy(DriverTimeoutException.java:34)
1条答案
按热度按时间r8xiu3jd1#
我们遇到了类似的问题,并尝试了您的确切步骤第一。driver examples code比搅拌我们在正确的方向。我们有一个自定义的cassandra配置与排除自动配置:
运行Spring启动起动器父版本2.3.0.RELEASE。
cassandra 配置: