推荐阅读:报错原因详解
报错信息
Caused by
: java
.lang
.IllegalArgumentException
: Could not resolve placeholder
'USER_NICK_NAME' in value
"${USER_NICK_NAME}"
原因分析
问题的产生是由于有多个properties文件造成的,如果再第一个properties文件中没有找,就不认为没有了,不继续找下一个properties文件.
如 serviceA 和 serviceB 都需要依赖 commons-service , 而commons-service使用了serviceA中的application.properties, 此时,serviceA就可以正常启动,serviceB不可以启动,因为启动serviceB时,commons-service没有在serviceB中找到application.properties文件
解决
在启动类中增加如下代码:
@Bean
public static PropertySourcesPlaceholderConfigurer
placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer c
= new PropertySourcesPlaceholderConfigurer();
c
.setIgnoreUnresolvablePlaceholders(true);
return c
;
}