【问题标题】:Spring cannot find key store fileSpring找不到密钥库文件
【发布时间】:2017-04-03 14:40:01
【问题描述】:

我有这个文件结构;

然后在我的 beans xml 配置上我有;

但是当我启动服务器时,我得到一个FileNotFoundException /store/thestore.jks

我错过了什么?提前致谢。

【问题讨论】:

  • //store/thestore.jks 中的前导?试试store/thestore.jks。我想不出别的了; IMO 看起来不错。
  • @ɐuıɥɔɐɯ 仍在获取; java.io.FileNotFoundException: store\thestore.jks (The system cannot find the path specified)
  • 请包含堆栈跟踪。
  • 能否将thestore.jks 复制到resources/store 之外)并将条目修改为<prop key="keyStorePath">classpath:thestore.jks</prop>?也可以试试file:thestore.jks。此外,就像@11thdimension 所说,用你的堆栈跟踪更新问题......

标签: java spring spring-boot restlet-2.0


【解决方案1】:

这里根据源代码com.noelios.restlet.util.DefaultSslContextFactory.createSslContext()

190            FileInputStream keyStoreInputStream = null;
191            try {
192                keyStoreInputStream = ((this.keyStorePath != null) && (!"NONE"
193                        .equals(this.keyStorePath))) ? new FileInputStream(
194                        this.keyStorePath) : null;
195                keyStore.load(keyStoreInputStream, this.keyStorePassword);

它使用FileInputStream,这意味着它将尝试从文件系统而不是从JAR本身读取文件。

您必须将 jks 文件放在 JAR 之外并提供它的绝对路径。

例如

<prop key="keyStorePath">C:/store/thestore.jks</prop>

【讨论】:

  • 在项目外提供文件的绝对路径解决了我的问题