开发环境
名称 | 版本 |
---|---|
操作系统 | Windows 10 X64 |
JDK | JDK1.8(jdk-8u151-windows-x64) |
IntelliJ IDEA | IntelliJ IDEA 2018.3 |
Maven | Maven 3.6.0 |
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders
问题描述
发布测试环境之后,访问接口失败,首先使用了下面的命令查看日志
tail -f /data/logs/server.log
出现下面的错误
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:851)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:595)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376)
... 41 common frames omitted
这里并没有明确说哪里的错误
原因分析
使用 cat /data/logs/server.log
查看完整的日志
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-01 10:31:21.704 [] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'systemConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'system.gas.url' in value "Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-01 10:31:21.704 [] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'systemConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'system.gas.url' in value "${system.gas.url}"
"
发现了有这一段,是 application.yml
里面没有配置项 {system.gas.url}
导致的~
问题解决
application.yml
加入配置项 {system.gas.url}
之后,问题解决。
Could not resolve placeholder
问题描述
- 项目启动报错
Could not resolve placeholder 'server.servlet.context-path' in value "${server.servlet.context-path}"
但是我找到项目的 application.yml
文件,发现是有下面的配置的
server:
port: 18804
servlet:
context-path:
问题分析
后来发现,项目启动,找的竟然是父项目的配置文件,而父项目的配置文件中,没有上面那个配置,所以报错。
通过对比,发现是项目资源文件夹的名称不对
原因是
resource
这个文件夹名称不对,导致项目启动找到的是父工程的配置文件。- 需要把
resource
修改为resources