java - 如何在启用 Cloud Config Server 和 SSH 的 Spring Boot 应用程序中从“Resources”文件夹中读取 known_hosts 文件
问题描述
我有一个使用 @EnableConfigServer 注释启用配置服务器的 Spring Boot 应用程序。配置服务器使用 SSH 访问密钥连接到托管在 Bitbucket.org 上的 Git 存储库。由于 Spring Boot 应用程序旨在部署到 Amazon Web Services,因此我希望在项目中包含用于 SSH 的“主机”文件。Spring对此有一个属性:
spring.cloud.config.server.git.known-hosts-file
我面临的问题如下:KnownHostsFileValidator(来自spring config的一个类)尝试使用以下代码验证文件是否存在:
new File(knownHostsFile).exists()
如果我想将我的 hosts 文件包含在要打包到 jar 中的资源目录中,那么此验证将失败,因为我为 known-hosts-file 属性提供的文件名未指向“资源”目录。
我的问题是:执行“new File(filePath)”时,known-hosts-file 的属性应该如何实际指向资源目录中的文件?
解决方案
推荐阅读
- c# - 无法使用 C# SmtpClient 通过 smtp.office365.com 更改 From email 的显示名称
- php - 如何在 laravel 中使用 jquery 进行模态编辑?
- arrays - 从范围值VBA创建数组
- delphi - 在 Delphi/Lazarus 中处理项目共享库的文件夹结构
- mysql - 包含 IF 或 CASE 的 MySQL 查询以选择非活动用户
- android - 如何在不初始化的情况下在 Kotlin 中创建变量?
- google-sheets - 在 Google 表格的一组数据中添加空白行
- eclipse - ubuntu 18 上 Eclipse 中的键盘快捷键
- c++ - 共享指针和具有自定义删除器的唯一指针之间的语法差异背后的任何原因
- face-detection - 使用 IR 图像进行人脸检测