有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java中的Cassandra身份验证异常

我正在使用DataStax驱动程序连接到Cassandra节点。下面是接头的代码

public void connect(String node, Integer port, String username, String password) throws Exception {
        try {
            Builder b = Cluster.builder().addContactPoint(node).withCredentials(username.trim(), password.trim());
            if (port != null) {
                b.withPort(port);
            }
            cluster = b.build();

            session = cluster.connect();
        } catch (Exception e) {
            throw new Exception("can not connect to the node :"+e.getMessage());
        }
    }

我在卡桑德拉设置了验证器。yaml文件

authenticator: PasswordAuthenticator

调用connect方法时,显示以下错误:

Authentication error on host localhost/127.0.0.1:9042: Host localhost/127.0.0.1:9042 requires authentication, but no authenticator found in Cluster configuration

cqlsh外壳能够使用与Cassandra相同的配置连接到节点。有人能告诉我这里缺少什么吗

编辑: 异常堆栈 在

com.datastax.driver.core.AuthProvider$1.newAuthenticator(AuthProvider.java:40) at com.datastax.driver.core.Connection$5.apply(Connection.java:259) at com.datastax.driver.core.Connection$5.apply(Connection.java:244) at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:211) at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:200) at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:130) at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902) at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813) at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:655) at com.datastax.driver.core.Connection$Future.onSet(Connection.java:1302) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1083) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1006) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:141) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:745)


共 (1) 个答案

  1. # 1 楼答案

    解决:

    错误是由于一些后台线程试图在没有身份验证的情况下连接到服务器,这些线程在以前的调试会话中未终止