我正在升级到Spring Boot 2.3.1.Release版本。由于Java驱动程序升级为v4,Spring Data Cassandra发生了重大变化。应用程序启动时出现DriverTimeout异常,导致我陷入困境。
com.datastax.oss.driver.api.core.DriverTimeoutException: [s0|control|id: 0x8572a9d7, L:/My_IPv4:Random_Port - R:/Cassandra_Server:Port] Protocol initialization request, step 1 (OPTIONS): timed out after 500 ms
我的Cassandra配置:
@Bean(name = "mySession")
@Primary
public CqlSession session() {
String containerIpAddress = getContactPoints();
int containerPort = getPort();
InetSocketAddress containerEndPoint = new InetSocketAddress(containerIpAddress, containerPort);
return CqlSession.builder().withLocalDatacenter(getLocalDataCenter())
.addContactPoint(containerEndPoint)
.withAuthCredentials(dbProperties.getCassandraUserName(), dbProperties.getCassandraPassword())
.withKeyspace(getKeyspaceName()).build();
}
我还尝试使用DriverConfigLoader选项,通过显式设置连接超时时间来实现:
@Bean(name = "mySession")
@Primary
public CqlSession session() {
String containerIpAddress = getContactPoints();
int containerPort = getPort();
InetSocketAddress containerEndPoint = new InetSocketAddress(containerIpAddress, containerPort);
DriverConfigLoader loader =
DriverConfigLoader.programmaticBuilder()
.withDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, Duration.ofSeconds(5))
.build();
return CqlSession.builder().withLocalDatacenter(getLocalDataCenter())
.withConfigLoader(loader)
.addContactPoint(containerEndPoint)
.withAuthCredentials(dbProperties.getCassandraUserName(), dbProperties.getCassandraPassword())
.withKeyspace(getKeyspaceName()).build();
}
尝试过多种方法,但都无济于事,仍出现相同的异常。我当前使用的Spring Boot版本是2.2.0.Release,甚至没有指定任何超时时间,但它仍然正常工作。如何解决这个问题?