在运行configclient项目时发生以下错误:
2017-08-10 22:41:52.006 WARN 59068 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configClientApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'foo' in string value "${foo}"
2017-08-10 22:41:52.012 INFO 59068 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
经过仔细排查,配置文件和代码都没有问题,就是一直报错,后来发现configclient项目不能在maven module中正确运行,特别是跟config server在一个maven project中,原因是pom。xml的依赖造成的,作为config client不能有以下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
否则会报错,因此如果config client和config server在同一个项目中则要注意依赖问题,而新建一个maven project可以比较容易的避免上述问题。