我正在尝试通过我的 spring-boot-3 多模块软件连接到 amazon-keyspace AWS Casandra,但它尝试连接 localhost / endPoint=/127.0.0.1:9042。 这是我的一些构建 gradle
plugins {
java
id("org.springframework.boot") version "3.0.1" apply false
id("io.spring.dependency-management") version "1.1.0"
id("io.freefair.lombok") version "6.6.1"
}
java.sourceCompatibility = JavaVersion.VERSION_17
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-cassandra-reactive")
implementation("software.aws.mcs:aws-sigv4-auth-cassandra-java-driver-plugin:4.0.8")
...
}
尝试不同的 application.yml 文件并添加和删除一些设置以查看差异
`
#new settings
spring:
cassandra:
keyspace-name: my-existing-keyspace
schema-action: none
config: keyspaces-application.conf
local-datacenter: eu-north-1
contact-points: cassandra.eu-north-1.amazonaws.com:9142
#Depricated one
spring:
data:
cassandra:
keyspace-name: my-existing-keyspace
schema-action: none
config: keyspaces-application.conf
local-datacenter: eu-north-1
contact-points: cassandra.eu-north-1.amazonaws.com:9142`
这是我的 keyspaces-application.conf :
datastax-java-driver {
basic.contact-points = [ "cassandra.eu-north-1.amazonaws.com:9142"]
advanced.auth-provider{
class = PlainTextAuthProvider
username = "my existing username"
在这里输入
password = "my existing password"
}
basic.load-balancing-policy {
local-datacenter = "eu-north-1"
slow-replica-avoidance = false
}
advanced.ssl-engine-factory {
class = DefaultSslEngineFactory
truststore-path = "/home/ec2-user/cassandra_truststore.jks"
truststore-password = "my-truststore-password"
hostname-validation = false
}
}
但它尝试连接本地主机 1
这是一些日志:
`Error connecting to Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=3d061dd6), trying next node (ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException))
WARN 24461 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myRepositoryImpl' defined in URL [jar:file:/home/ec2-user/my-service/my-container/build/libs/my-container-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/my-dataaccess-0.0.1-SNAPSHOT.jar!/com/anything/MyRepositoryImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'myCasandraRepository' defined in ******.MyRepository defined in @EnableReactiveCassandraRepositories declared on ContainerApplication: Cannot resolve reference to bean 'reactiveCassandraTemplate' while setting bean property 'reactiveCassandraOperations'`
`Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reactiveCassandraTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveCassandraTemplate' parameter 0: Error creating bean with name 'reactiveCassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveCassandraSession' parameter 0: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception with message: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllError`
`Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception with message: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=3d061dd6): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]`
我正在尝试通过 spring boot 3 应用程序和 datastax-v4 连接 amazon-keyspace aws casandra 但它尝试连接到 localhost endPoint=/127.0.0.1:9042 可能是我错过了一个配置,或者 spring boot 3 可能更改了一些配置,或者需要对反应设置进行一些更改
正确的配置是
spring.cassandra.contact-points=host:port
我看你有
spring:
cassandra:
keyspace-name: my-existing-keyspace
schema-action: none
config: keyspaces-application.conf
local-datacenter: eu-north-1
contact-points: cassandra.eu-north-1.amazonaws.com:9142
你有缩进问题。应该是下面这样
spring:
cassandra:
keyspace-name: my-existing-keyspace
schema-action: none
config: keyspaces-application.conf
local-datacenter: eu-north-1
contact-points: cassandra.eu-north-1.amazonaws.com:9142
如果您不提供该制表符,配置将返回默认值 127.0.0.1:9042 并且不会抛出任何异常。