Spring-boot:如何从class路径或文件系统加载钥匙店资源文件?
我的Spring-Boot应用程序需要通过Java密钥库访问私钥。对于测试,我想使用一个在类Path上可用的测试密钥库(因此我可以轻松地执行应用程序作为集成测试的一部分),而在生产中,我想使用一些外部卷中的密钥库(例如,例如,安装在容器中作为K8秘密)。
我知道Spring-Boot @Value
注释使我可以注入资源。但是,我看不出如何使尊重春季环境(例如,测试或生产)的动态动态。 Spring-boot是否提供了解决上述问题的开箱即用途方式,还是我需要编写自己的Bean来根据部署环境加载正确的密钥库?
My spring-boot application requires access to private keys via a Java keystore. For testing, I would like to use a test keystore that is available on the classpath (so I can easily execute the application as part of an integration test), while in production I would like to use a keystore from some external volume (e.g., mounted inside a container as k8 secret).
I know that the spring-boot @Value
annotation allows me to inject a resource. However, I don't see how it can be made dynamic to respect the spring environment (e.g., test or production). Does spring-boot provide an out-of-the-box way to solve the above problem, or do I need to write my own bean to load the correct keystore depending on the deployment environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将属性用于资源路径,并根据活动配置文件以不同的方式设置应用程序中的属性值。
application.yml:
You can use a property for the resource path and set that property values in your application props differently based on an active profile.
application.yml: