springboot報錯無法讀取配置檔案中的屬性:Could not resolve placeholder ‘xxxx‘ in value “${xxxx}
現象:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'constantPropertiesUtils': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'custom.filehost' in value "${custom.filehost}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:403) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'custom.filehost' in value "${custom.filehost}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:908) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1228) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 17 common frames omitted
環境:
系統:windows 10
IDE:vs code
編譯工具:gradle
解決:
因為發現application.properties檔案裡其他屬性都能被@Value註解識別,只有新增的屬性不能,於是想到可能是某些快取問題導致的吧。
首先,嘗試執行‘gradle clean build’命令清理工程並重新構建,結果發現仍然報相同的錯誤。
接著嘗試在vs code中開啟命令皮膚輸入"clean the java language server workspace"並執行,重新開啟vs code後再執行此錯誤就不再出現了。
總結:
最終還是沒弄清楚這個問題的原因,只是憑藉經驗取巧解決的,希望有知道問題原因的大神能分享一下。
PS:使用vs code開發經常遇到各種奇奇怪怪的問題,在花費大量時間分析問題或嘗試各種解決方案無效後,使用命令"clean the java language server workspace"重啟vs code往往都能解決問題。這也算一個收穫吧,以後遇到類似問題先用clean這招試一下,說不定就解決了,還能節省時間。
相關文章
- XMl 檔案屬性的讀取XML
- Java屬性檔案的讀取Java
- Spring中利用配置檔案和@value注入屬性值Spring
- 【springboot讀取配置檔案】@ConfigurationProperties、@PropertySource和@ValueSpring Boot
- 報錯xxxx of undefinedUndefined
- Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}"Redis
- Could not resolve host: 'localhost 報錯解決辦法localhost
- springboot讀取配置檔案Spring Boot
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- Java系列-如何讀取.properties屬性檔案Java
- java中讀取配置檔案Java
- 在Progress中獲取檔案屬性
- SpringBoot基礎學習(二) SpringBoot全域性配置檔案及配置檔案屬性值注入Spring Boot
- SpringBoot專案中獲取配置檔案的配置資訊Spring Boot
- Golang專案中讀取配置檔案Golang
- SpringBoot配置檔案讀取過程分析Spring Boot
- java中讀取.properties配置檔案Java
- python中無法正確讀取.mat檔案的解決辦法Python
- docker 啟動 jenkins,配置 mvn 卻無法使用 shell 讀取配置檔案DockerJenkins
- 無法讀取來源檔案或磁碟
- Spring MVC 通過 @PropertySource和@Value 來讀取配置檔案SpringMVC
- could not autowire. No beans of 'xxxx' 問題解決Bean
- R語言 - 讀取CSV檔案報錯R語言
- SpringBoot(二)_專案屬性配置Spring Boot
- Win7 IIS7 配置錯誤由於許可權不足而無法讀取配置檔案的解決辦法Win7
- yml:java.lang.IllegalArgumentException: Could not resolve placeholder ‘jdbc.driverClassName‘JavaExceptionJDBC
- springboot 執行 jar 包讀取外部配置檔案Spring BootJAR
- value xxx for the flexfield segment customer:does not exist in the value set xxxxFlex
- viper 讀取配置檔案
- go配置檔案讀取Go
- 獲取選中select下拉選單的value屬性值
- pod install 和 rvm install ruby-xxxx報錯解決辦法
- 如何在python中讀取配置檔案Python
- 文摘:在EJB中讀取XML配置檔案XML
- SpringBoot載入配置檔案(@PropertySource@importSource@Value)Spring BootImport
- Maven中的-D(Properties屬性)和-P(Profiles配置檔案)Maven
- PL/SQL Developer啟動時報錯,Initialization error could not load xxxx\oci.dllSQLDeveloperError
- 快應用如何避免讀取undefined變數的屬性導致報錯Undefined變數