我向AWS部署了Spring引導服務,而application.properties引用了作爲部署過程一部分設置的OS環境變量之一。 Spring Boot似乎在引導時無法解析OS環境變量。春季開機無法解析OS環境變量?
如果我贊同這似乎是正確設置變量 -
[email protected]:~$ echo $EC2_INSTANCE_ID
i-de8c136d
application.properties文件指的是可變的,如下 -
service.hostId=aws-${EC2_INSTANCE_ID}
我看到下面的錯誤啓動本應用程序時 -
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.foo.services.registration.config; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'EC2_INSTANCE_ID' in string value "${EC2_INSTANCE_ID}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
任何想法我可能做錯了什麼?在application.properties文件中引用時是否需要添加任何前綴,如「sys:」?
您確定該變量是全局可用的,而不僅僅是本地shell嗎? –
是的,變量在/ etc/environment文件中定義,它通過/etc/bash.bashrc來源。登錄到主機而不是回顯作品。可能是我完全錯誤的路徑,但一些在論壇上閱讀提示,init腳本可能不使用交互式登錄shell。 – slad