简体   繁体   English

Spring-boot 应用程序 - 使用 su 执行 jar 时未加载外部属性 -

[英]Spring-boot application - External properties not loaded when jar execute with su -

I have an application in spring-boot 2.2.4我在 spring-boot 2.2.4 中有一个应用程序

When I launch the application like this :当我像这样启动应用程序时:

java -jar ../batch-pj-clean-nas/target/batch-pj-clean-nas-1.0.0-SNAPSHOT.jar -Dconfig.location=application.properties java -jar ../batch-pj-clean-nas/target/batch-pj-clean-nas-1.0.0-SNAPSHOT.jar -Dconfig.location=application.properties

Everything is ok.一切都好。

When I try like that :当我这样尝试时:

su - sbert -c "java -jar /home/sbert/workspace/pj/batch-pj-clean-nas/target/batch-pj-clean-nas-1.0.0-SNAPSHOT.jar -Dconfig.location=application.properties"

the properties is not loaded未加载属性

Could not resolve placeholder 'nas.base.directory' in value "${nas.base.directory}"无法解析值“${nas.base.directory}”中的占位符“nas.base.directory”

I try with OS ubuntu, RH8 and spring-boot 2.2.4 or 2.1.3 and replace -Dconfig.location by --spring.config.location我尝试使用操作系统 ubuntu、RH8 和 spring-boot 2.2.4 或 2.1.3 并用 --spring.config.location 替换 -Dconfig.location

如果要从 Jar 外部加载它,请提供 application.properties 文件的完整路径

I finally found the reason : I have to use :我终于找到了原因:我必须使用:

su sbert -c su sbert -c

instead of代替

su - sbert -c su - sbert -c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM