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