Springboot配置文件加载源码解读

1、问题触发:

使用java -jar -Dfile.encoding=utf-8  -Dspring.config.location=./application.yml XXX.jar,报错“Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'global': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'agent.version' in value "${agent.version}"”,但是如果将 -Dspring.config.location=./application.yml去掉,直接使用使用java -jar -Dfile.encoding=utf-8 XXX.jar却可以正常运行?

2024-09-05 14:48:52,439 INFO org.springframework.boot.StartupInfoLogger [main] Starting Application v2.3.2.RELEASE on DESKTOP-DJM8EO3 with PID 17112 (D:\jar\agent\StationControlAgent.jar started by zjt in D:\jar\agent)
2024-09-05 14:48:52,451 INFO org.springframework.boot.SpringApplication [main] The following profiles are active: test
2024-09-05 14:48:57,222 INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer [main] Tomcat initialized with port(s): 8088 (http)
2024-09-05 14:48:57,258 INFO org.apache.juli.logging.DirectJDKLog [main] Initializing ProtocolHandler ["http-nio-8088"]
2024-09-05 14:48:57,262 INFO org.apache.juli.logging.DirectJDKLog [main] Starting service [Tomcat]
2024-09-05 14:48:57,262 INFO org.apache.juli.logging.DirectJDKLog [main] Starting Servlet engine: [Apache Tomcat/9.0.37]
2024-09-05 14:48:57,518 INFO org.apache.juli.logging.DirectJDKLog [main] Initializing Spring embedded WebApplicationContext
2024-09-05 14:48:57,522 INFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext [main] Root WebApplicationContext: initialization completed in 4815 ms
2024-09-05 14:48:57,738 WARN org.springframework.context.support.AbstractApplicationContext [main] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值