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這招試一下,說不定就解決了,還能節省時間。
相關文章
- 報錯xxxx of undefinedUndefined
- 【springboot讀取配置檔案】@ConfigurationProperties、@PropertySource和@ValueSpring Boot
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- springboot讀取配置檔案Spring Boot
- could not autowire. No beans of 'xxxx' 問題解決Bean
- pod install 和 rvm install ruby-xxxx報錯解決辦法
- idea啟用後提示We could not validate your license xxxx解決辦法Idea
- SpringBoot基礎學習(二) SpringBoot全域性配置檔案及配置檔案屬性值注入Spring Boot
- SpringBoot配置檔案讀取過程分析Spring Boot
- tomcat-啟動報錯Multiple Contexts have a path of "/xxxx"TomcatContext
- yml:java.lang.IllegalArgumentException: Could not resolve placeholder ‘jdbc.driverClassName‘JavaExceptionJDBC
- Linux awk 中 xxxx的應用Linux
- java中讀取配置檔案Java
- SpringBoot專案中獲取配置檔案的配置資訊Spring Boot
- docker 啟動 jenkins,配置 mvn 卻無法使用 shell 讀取配置檔案DockerJenkins
- SpringBoot(二)_專案屬性配置Spring Boot
- Vue init webpack xxxx project 報錯處理(connect ETIMEDOUT 192.30.253.112)VueWebProject
- PostgreSQL cache lookup failed for type XXXX 錯誤SQLAI
- 寫一條一行的4為數字,每隔4個數字空一格 xxxx xxxx xxxx xxx就是xxxx這樣的格式
- Golang專案中讀取配置檔案Golang
- 01.SpringBoot開發雜記-使用工具類,靜態讀取配置檔案中的配置的寫法Spring Boot
- springboot 執行 jar 包讀取外部配置檔案Spring BootJAR
- SpringBoot通過@ConfigurationProperties註解和@Value讀取資原始檔中的值Spring Boot
- SpringBoot載入配置檔案(@PropertySource@importSource@Value)Spring BootImport
- 無法讀取來源檔案或磁碟
- Win7 IIS7 配置錯誤由於許可權不足而無法讀取配置檔案的解決辦法Win7
- R語言 - 讀取CSV檔案報錯R語言
- 如何在python中讀取配置檔案Python
- AndroidStudio升級報錯Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve cAndroidAPPCompile
- eclipse配置Maven Settings.xml檔案報錯:Could not read settings.xmlEclipseMavenXML
- VSCode報錯:cnpm : 無法載入檔案VSCodeNPM
- IOC - 讀取配置檔案
- viper 讀取配置檔案
- go配置檔案讀取Go
- SpringBoot配置屬性二Spring Boot
- Android讀取配置檔案的方法Android
- Springboot整合MongoDB儲存檔案、讀取檔案Spring BootMongoDB
- 錯誤 CS0006 Metadata file 'E:\專案名稱\xxxx.dll'