因此,我有一个Spring Boot胖子,其配置需要从.pem
文件中定义的绝对路径加载application.properties
文件。
我这样定义路径:
security.jwt.public-key=/opt/samara/staging.pem
用法如下:
@Value("\${security.jwt.public-key}")
lateinit var publicKey: Resource
这是目录结构:
root@samara:/opt/samara# ls -lsh
-rwxr-xr-x 1 root root 44M Nov 27 07:50 app.jar
-rwxr-xr-x 1 root root 2.0K Nov 27 07:53 staging.pem
-rwxr-xr-x 1 root root 1.2K Nov 27 08:29 application.properties
但是当我试图像这样运行它时:
root@samara:/opt/samara# java -jar app.jar
此操作失败:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/opt/samara/staging.pem]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:158) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
实际上,我从另一台计算机上复制了这些文件,并且该文件在该计算机上运行完美,但是我不知道为什么它在新计算机上失败。谢谢。
答案 0 :(得分:0)
阅读以下内容: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#resources
我将路径定义更改为:
security.jwt.public-key=file:/opt/samara/staging.pem
成功了!