gpt4 book ai didi

java - 尝试使用 Spring Config Server 时如何修复 "There are not any available ciphers"JSch 异常?

转载 作者:行者123 更新时间:2023-11-29 04:08:38 26 4
gpt4 key购买 nike

我正在尝试让嵌入式 Spring Config Server 实现正常工作,以从 GitHub 读取配置。我正在学习本教程:

https://mromeh.com/2017/12/04/spring-boot-with-embedded-config-server-via-spring-cloud-config/

当我的 Spring Boot 应用程序尝试启动时出现以下异常:

Caused by: com.jcraft.jsch.JSchException: There are not any available ciphers. at com.jcraft.jsch.Session.send_kexinit(Session.java:629) at com.jcraft.jsch.Session.connect(Session.java:307) at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:146) ... 23 more

在我的代码中,唯一有趣的部分是我的 bootstrap.yml 文件,它看起来像这样:

spring:
application:
name: DemoApplication.yml

---
spring:
cloud:
config:
failFast: true
server:
bootstrap: true
git:
uri: git@github.com:mycompany/demo-config.git

我在 MacOS 上运行 OpenJDK 8 v212,运行以下命令:

#> java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)

我已经搜索了 Spring 代码和文档,但尚未找到有关传递配置参数或添加代码以影响 Spring 使用的 Jsch session 的构建方式的任何信息。我发现的一切都表明我正在做的事情应该会奏效。

我不知道从这里去哪里。谁能告诉我我缺少什么……我需要做什么才能解决这个问题?

最佳答案

为了巩固前面的评论...

在幕后,Spring 使用 JGit建立 SSH 连接。默认情况下,这使用 JSch 建立 SSH 连接,该连接由 ~/.ssh/config 文件配置。

The wiki也有如何绕过 JSch 和使用原生 ssh 命令的细节,可以设置 GIT_SSH 环境变量,例如到 /usr/bin/ssh 在 OS X 或 Linux 中,甚至像 C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe 这样的东西。


在有关如何避免依赖于设置环境变量的评论之后,请注意如何使用 TransportGitSsh.useExtSession() 中的 SystemReader 检查 GIT_SSH 环境变量|方法。

这意味着一种方法是覆盖 SystemReader 类。虽然它不是一个小接口(interface),因此会涉及相当多的包装代码——使用 getenv() 中的自定义位:

import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;

public class CustomSystemReader extends SystemReader {
private final SystemReader systemReader;

public CustomSystemReader(SystemReader systemReader) {
this.systemReader = systemReader;
}

@Override
public String getHostname() {
return systemReader.getHostname();
}

@Override
public String getenv(String variable) {
if ("GIT_SSH".equals(variable))
return "/usr/bin/ssh";
return systemReader.getenv(variable);
}

@Override
public String getProperty(String key) {
return systemReader.getProperty(key);
}

@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return systemReader.openUserConfig(parent, fs);
}

@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
return systemReader.openSystemConfig(parent, fs);
}

@Override
public long getCurrentTime() {
return systemReader.getCurrentTime();
}

@Override
public int getTimezone(long when) {
return systemReader.getTimezone(when);
}
}

然后可以这样连接:

    SystemReader.setInstance(
new CustomSystemReader(SystemReader.getInstance()));

关于java - 尝试使用 Spring Config Server 时如何修复 "There are not any available ciphers"JSch 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56591493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com