你好,我正在使用Spring Integration的文件轮询器,我们最近迁移到了Java 17。Spring Integration从5.5.15移至6.0.1
我的老朋友是:
@Bean
public SessionFactory<LsEntry> sftpSessionFactory(){
DefaultSftpSessionFactory sf = new DefaultSftpSessionFactory();
sf.setHost(serverhost);
sf.setPort(portname);
sf.setUser(username);
Resource resource = resourceLoader.getResource(sftpKeyPrivateKey);
sf.setPrivateKey(resource);
sf.setPrivateKeyPassphrase(sftpKeyPrivateKeyPassword);
sf.setAllowUnknownKeys(true);
return new CachingSessionFactory<LsEntry> (sf);
}
我的Session Factory的新代码看起来像这样:
@Bean
public SessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry> sftpSessionFactory()
{
DefaultSftpSessionFactory sf = new DefaultSftpSessionFactory();
sf.setHost(serverhost);
sf.setPort(portname);
sf.setUser(username);
Resource resource = resourceLoader.getResource(sftpKeyPrivateKey);
sf.setPrivateKey(resource);
sf.setPrivateKeyPassphrase(sftpKeyPrivateKeyPassword);
sf.setAllowUnknownKeys(true);
return new CachingSessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry(sf);
}
其他一切都保持不变。旧代码按预期工作,但在新代码中,当我启动我的服务时,我得到以下异常:
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:291)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:67)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:85)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:82)
at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:206)
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:187) ... 23 more Caused by: org.apache.sshd.common.SshException: No more authentication methods available
at org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:127)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:39)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:32)
at org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:43)
at org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:68)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initClientSession(DefaultSftpSessionFactory.java:318)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:281) ... 28 more
Caused by: org.apache.sshd.common.SshException: No more authentication methods available
1条答案
按热度按时间z18hc3ub1#
在Java 17中,我们必须使用Apache中的DirEntry而不是LsEntry。使用JSCH可以在putty ssh-rsa中创建ppk文件。但是在Apache中,我们需要以
-----BEGIN OPENSSH PRIVATE KEY-----
开头的密钥。因为内部代码是初学者Apache为了加载而拥有的。因此,我们可以将我们的密钥转换为OPENSSH私钥,它将按预期工作。
ssh-keygen -p -N“”-f /path/to/key