org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.configController':
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:
Could not resolve placeholder 'nacos.config' in value "${nacos.config}"
根据上面的错误,找了很多都说nacos上dataId名没按照 p r e f i x − {prefix}- prefix−{spring.profile.active}.${file-extension}配置导致错误。
或者bootstrap.yml的file-extension没配为yml。
按照例子对比了很多次确定没有错误,结果还是报错。
最后根据启动信息,发现根本没读取到bootstrap.yml的配置(Located property source: [BootstrapPropertySource {name=‘bootstrapProperties-null,DEFAULT_GROUP’}])
2020-08-31 10:12:36.859 WARN 9104 --- [ restartedMain] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[null.properties] & group[DEFAULT_GROUP]
2020-08-31 10:12:36.861 INFO 9104 --- [ restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-null.properties,DEFAULT_GROUP'}]
2020-08-31 10:12:36.867 INFO 9104 --- [ restartedMain] com.mk.NacosConfigMain : No active profile set, falling back to default profiles: default
2020-08-31 10:12:39.395 WARN 9104 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.configController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'nacos.config' in value "${nacos.config}"
2020-08-31 10:12:39.398 INFO 9104 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-08-31 10:12:39.400 INFO 9104 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
解决方法:注释了pom文件的packaing就可以了
创建子项目的时候弄错了pom.xml配置
问题原因:可能是加了packaing变为父级项目的原因,有哪位大佬懂的可以评论下……
修改后启动信息变为({name=‘bootstrapProperties-nacos-config.yml,DEFAULT_GROUP’}, BootstrapPropertySource {name=‘bootstrapProperties-nacos-config,DEFAULT_GROUP’}])
2020-08-31 10:19:46.260 INFO 9812 --- [ restartedMain] b.c.PropertySourceBootstrapConfiguration :
Located property source: [BootstrapPropertySource {name='bootstrapProperties-nacos-config.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-nacos-config,DEFAULT_GROUP'}]
2020-08-31 10:19:49.795 INFO 9812 --- [ restartedMain] c.a.n.client.config.impl.ClientWorker :
[fixed-localhost_8848] [subscribe] nacos-config+DEFAULT_GROUP
2020-08-31 10:19:49.796 INFO 9812 --- [ restartedMain] c.a.nacos.client.config.impl.CacheData :
[fixed-localhost_8848] [add-listener] ok, tenant=, dataId=nacos-config, group=DEFAULT_GROUP, cnt=1