英文:
Inject place holder values at Spring boot application.yml file using intellij at run time
问题
我正在使用IntelliJ运行我的Spring Boot应用程序,该应用程序具有带有占位符的application.yml文件。占位符的值应该根据环境配置在运行时注入。
server:
port: ${SERVER_PORT}
我尝试通过在应用程序运行的环境变量部分中传递占位符值来从IntelliJ运行Spring Boot应用程序。
在运行此应用程序时,我遇到以下错误:
自动装配依赖项的注入失败;嵌套异常是java.lang.IllegalArgumentException: 在值 "${SERVER_PORT}" 中无法解析占位符 'SERVER_PORT'
原因:java.lang.IllegalArgumentException: 在值 "${SERVER_PORT}" 中无法解析占位符 'SERVER_PORT'
英文:
I am using Intellj to run my Spring Boot application which has application.yml file with place holder. The values of placeholder should be injected at run time depending upon the environment configuration.
server:
port: ${SERVER_PORT}
I am trying to run the Spring Boot application from Intellij by passing the place holder value in the Environment Variable section of application run
I am getting below error while running this application:
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'SERVER_PORT' in value "${SERVER_PORT}"
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'SERVER_PORT' in value "${SERVER_PORT}"
答案1
得分: 2
可能是因为你的变量赋值是递归的。SERVER_PORT
是与 server.port
相同的属性,或者是:
server:
port:
在这里查看链接,获取配置属性和其优先级顺序的源列表。
尝试从你的 YAML 文件中移除这个部分。如果你声明了环境变量 server.port
或者 SERVER_PORT
,Spring Boot 将会获取并使用它。
英文:
Could be this is because your variable assignment is recursive, in a way. SERVER_PORT
is the same property as server.port
or
server:
port:
See here for a list of sources for configuration properties and their order of precedence.
Try removing the section from your yaml file. If you declare an environment variable server.port or SERVER_PORT then SpringBoot will pick it up and use it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论