1

在 Spring Boot 1.2.3.RELEASE 上尝试在 JDK 1.8、Windows 7 上设置 SSH。

我将 application.properties 配置为:

shell.ssh.port=2212
shell.ssh.enabled=true
shell.auth=simple
shell.auth.simple.user.name=user
shell.auth.simple.user.password=password

当应用程序启动并尝试通过 putty 访问它时,会出现以下异常:

java.lang.IllegalStateException: No session available
    at org.apache.sshd.common.AbstractSessionIoHandler.exceptionCaught(AbstractSessionIoHandler.java:52) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:697) ~[mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:791) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:111) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireExceptionCaught(DefaultIoFilterChain.java:471) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:359) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$700(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionCreated(DefaultIoFilterChain.java:771) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.IoFilterAdapter.sessionCreated(IoFilterAdapter.java:79) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireSessionCreated(DefaultIoFilterChain.java:350) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.service.IoServiceListenerSupport.fireSessionCreated(IoServiceListenerSupport.java:211) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:514) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:481) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$200(AbstractPollingIoProcessor.java:67) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1071) [mina-core-2.0.2.jar:na]
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) [mina-core-2.0.2.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: java.lang.AbstractMethodError: org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.loadKeys()[Ljava/security/KeyPair;
    at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.ServerSession.sendKexInit(ServerSession.java:331) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.ServerSession.<init>(ServerSession.java:92) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.SessionFactory.doCreateSession(SessionFactory.java:43) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.common.session.AbstractSessionFactory.createSession(AbstractSessionFactory.java:38) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.common.AbstractSessionIoHandler.sessionCreated(AbstractSessionIoHandler.java:37) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionCreated(DefaultIoFilterChain.java:643) ~[mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]

我在这里缺少什么吗?

谢谢。


更新:感谢指点。这是我的依赖树:

[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO]    +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO]    +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO]    |  +- org.apache.sshd:sshd-core:jar:0.6.0:compile
[INFO]    |  +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO]    |  |  \- net.sf.jpam:jpam:jar:1.1:compile
[INFO]    |  +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO]    |  \- org.apache.mina:mina-core:jar:2.0.2:compile
[INFO]    +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO]    +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO]    |  \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO]    +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO]    |  \- javax.mail:mail:jar:1.4.7:compile
[INFO]    |     \- javax.activation:activation:jar:1.1:compile
[INFO]    +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO]    \- org.codehaus.groovy:groovy:jar:2.3.11:compile

所有依赖项都从 spring-boot-starter-remote-shell 传递过来。我将尝试使用手动覆盖进行修复。

4

1 回答 1

3

我用jdk1.8开始了一个spring boot项目,添加了spring-boot-starter-remote-shellmaven依赖和你的配置,试了一下,一切都很顺利。

然而java.lang.AbstractMethodError,让我怀疑是类路径问题,所以我很快mvn dependency:tree在我的项目上运行了一个,除其他外,spring-boot-starter-remote-shell:jar:1.2.3.RELEASE它具有org.apache.sshd:sshd-core:jar:0.11.0传递依赖,如下所示。

[INFO] +- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] |  +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO] |  +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO] |  |  +- org.apache.sshd:sshd-core:jar:0.11.0:compile <===THIS ONE===
[INFO] |  |  +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO] |  |  |  \- net.sf.jpam:jpam:jar:1.1:compile
[INFO] |  |  +- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] |  |  +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO] |  |  \- org.apache.mina:mina-core:jar:2.0.7:compile
[INFO] |  +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO] |  +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO] |  |  \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO] |  +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO] |  |  \- javax.mail:mail:jar:1.4:compile
[INFO] |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO] |  \- org.codehaus.groovy:groovy:jar:2.3.11:compile

再次快速查看您的堆栈跟踪发现您似乎在类路径上有一个不同的版本,at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]所以我接下来要做的是手动将此版本指定为 pom.xml 中的依赖项。当我重新运行应用程序并尝试通过 SSH 连接时,我遇到了与您相同的异常。

还要查看这些类,该AbstractKeyPairProvider.loadKeys()方法具有不同的签名,这很可能会根据 0.11.0 合同而弄乱实现,例如URLKeyPairProvider

  • 0.6.0protected abstract KeyPair[] loadKeys();
  • 0.11.0public abstract Iterable<KeyPair> loadKeys();

方法不一致

所以,要么你也无意中添加了这个版本,要么你的一些其他依赖项正在引用它,有效地隐藏0.11.0在类路径上。在我的例子中,我启用了spring boot 执行器 HTTP 端点,确认了上述内容: 类路径顺序

总之,检查您的依赖关系树并找出sshd-core 0.6.0可能mina-core 2.0.2来自哪里并排除它们。

于 2015-04-28T20:36:21.500 回答