Java 升级到Spring boot 2.3.5.0版本后的Cassandra身份验证问题
我们正在升级到Spring boot 2.3.5.0版本。我们的应用程序将cassandra作为数据库之一,并在节点上启用了身份验证。在更新spring启动版本后尝试连接casssandra db时,我遇到了此异常,无法启动应用程序Java 升级到Spring boot 2.3.5.0版本后的Cassandra身份验证问题,java,spring-boot,cassandra,Java,Spring Boot,Cassandra,我们正在升级到Spring boot 2.3.5.0版本。我们的应用程序将cassandra作为数据库之一,并在节点上启用了身份验证。在更新spring启动版本后尝试连接casssandra db时,我遇到了此异常,无法启动应用程序 Authentication error on node <IP:PORT> requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authen
Authentication error on node <IP:PORT> requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured
}
我在构建CqlSession时提供用户名和密码,但仍面临此异常。有什么我做得不对吗?在较旧的Spring数据版本中,您可以使用:
CassandraClusterFactoryBean
。但这里是一个未来的例子,如果其他人在使用spring数据cassandra 3.0.1时遇到了用户名和密码身份验证的问题,就像滚动到页面末尾一样,那么您将看到CassandraClusterFactoryBean
被删除,而不是我们现在的CqlSessionFactoryBean
。因此,示例代码与
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.config.CqlSessionFactoryBean;
@Configuration
@EnableCassandraRepositories(basePackages = {"com.some.package"})
@ConfigurationProperties(prefix = "spring.data.cassandra")
@Getter
@Setter
public class CassandraConfig extends AbstractCassandraConfiguration {
private String keyspaceName;
private String contactPoints;
private int port;
private String localDataCenter;
private String username;
private String password;
@Bean
@Override
public CqlSessionFactoryBean cassandraSession() {
CqlSessionFactoryBean cassandraSession = super.cassandraSession();//super session should be called only once
cassandraSession.setUsername(username);
cassandraSession.setPassword(password);
return cassandraSession;
}
}
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.config.CqlSessionFactoryBean;
@Configuration
@EnableCassandraRepositories(basePackages = {"com.some.package"})
@ConfigurationProperties(prefix = "spring.data.cassandra")
@Getter
@Setter
public class CassandraConfig extends AbstractCassandraConfiguration {
private String keyspaceName;
private String contactPoints;
private int port;
private String localDataCenter;
private String username;
private String password;
@Bean
@Override
public CqlSessionFactoryBean cassandraSession() {
CqlSessionFactoryBean cassandraSession = super.cassandraSession();//super session should be called only once
cassandraSession.setUsername(username);
cassandraSession.setPassword(password);
return cassandraSession;
}
}