天天看点

SpringCloud alibaba使用Nacos读取变量报错 Could not resolve placeholder ‘xxx‘ in value “${xxx}“

前置条件

配置文件

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
      config:
        # 服务器地址
        server-addr: 127.0.0.1:8848
        # 后缀名
        file-extension: yml
        # 共享设置
        shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
           

调用位置

@Service
public class DemoServiceImpl implements DemoService{

    @Value("${abc}")
    private String abc;
    @Override
    public void getAbc() {
        System.out.println(abc);
    }
}
           

问题复现

SpringCloud alibaba使用Nacos读取变量报错 Could not resolve placeholder ‘xxx‘ in value “${xxx}“
D:\tools\jdk\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\tools\idea\idea\IntelliJ IDEA 2022.1.3\lib\idea_rt.jar=56145:D:\tools\idea\idea\IntelliJ IDEA 2022.1.3\bin" -Dfile.encoding=UTF-8 -classpath D:\tools\jdk\jre\lib\charsets.jar;D:\tools\jdk\jre\lib\deploy.jar;D:\tools\jdk\jre\lib\ext\access-bridge-64.jar;D:\tools\jdk\jre\lib\ext\cldrdata.jar;D:\tools\jdk\jre\lib\ext\dnsns.jar;D:\tools\jdk\jre\lib\ext\jaccess.jar;D:\tools\jdk\jre\lib\ext\jfxrt.jar;D:\tools\jdk\jre\lib\ext\localedata.jar;D:\tools\jdk\jre\lib\ext\nashorn.jar;D:\tools\jdk\jre\lib\ext\sunec.jar;D:\tools\jdk\jre\lib\ext\sunjce_provider.jar;D:\tools\jdk\jre\lib\ext\sunmscapi.jar;D:\tools\jdk\jre\lib\ext\sunpkcs11.jar;D:\tools\jdk\jre\lib\ext\zipfs.jar;D:\tools\jdk\jre\lib\javaws.jar;D:\tools\jdk\jre\lib\jce.jar;D:\tools\jdk\jre\lib\jfr.jar;D:\tools\jdk\jre\lib\jfxswt.jar;D:\tools\jdk\jre\lib\jsse.jar;D:\tools\jdk\jre\lib\management-agent.jar;D:\tools\jdk\jre\lib\plugin.jar;D:\tools\jdk\jre\lib\resources.jar;D:\tools\jdk\jre\lib\rt.jar;D:\study\code\demo-nacos-config\target\classes;D:\tools\m2\org\springframework\boot\spring-boot-starter-web\2.3.9.RELEASE\spring-boot-starter-web-2.3.9.RELEASE.jar;D:\tools\m2\org\springframework\boot\spring-boot-starter\2.3.9.RELEASE\spring-boot-starter-2.3.9.RELEASE.jar;D:\tools\m2\org\springframework\boot\spring-boot-starter-logging\2.3.9.RELEASE\spring-boot-starter-logging-2.3.9.RELEASE.jar;D:\tools\m2\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\tools\m2\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\tools\m2\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;D:\tools\m2\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;D:\tools\m2\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\tools\m2\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\tools\m2\org\springframework\spring-core\5.2.13.RELEASE\spring-core-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-jcl\5.2.13.RELEASE\spring-jcl-5.2.13.RELEASE.jar;D:\tools\m2\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\tools\m2\org\springframework\boot\spring-boot-starter-json\2.3.9.RELEASE\spring-boot-starter-json-2.3.9.RELEASE.jar;D:\tools\m2\com\fasterxml\jackson\core\jackson-databind\2.11.4\jackson-databind-2.11.4.jar;D:\tools\m2\com\fasterxml\jackson\core\jackson-annotations\2.11.4\jackson-annotations-2.11.4.jar;D:\tools\m2\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.4\jackson-datatype-jdk8-2.11.4.jar;D:\tools\m2\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.4\jackson-datatype-jsr310-2.11.4.jar;D:\tools\m2\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.4\jackson-module-parameter-names-2.11.4.jar;D:\tools\m2\org\springframework\boot\spring-boot-starter-tomcat\2.3.9.RELEASE\spring-boot-starter-tomcat-2.3.9.RELEASE.jar;D:\tools\m2\org\apache\tomcat\embed\tomcat-embed-core\9.0.43\tomcat-embed-core-9.0.43.jar;D:\tools\m2\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\tools\m2\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.43\tomcat-embed-websocket-9.0.43.jar;D:\tools\m2\org\springframework\spring-web\5.2.13.RELEASE\spring-web-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-beans\5.2.13.RELEASE\spring-beans-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-webmvc\5.2.13.RELEASE\spring-webmvc-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-aop\5.2.13.RELEASE\spring-aop-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-context\5.2.13.RELEASE\spring-context-5.2.13.RELEASE.jar;D:\tools\m2\org\springframework\spring-expression\5.2.13.RELEASE\spring-expression-5.2.13.RELEASE.jar;D:\tools\m2\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-discovery\2.2.3.RELEASE\spring-cloud-starter-alibaba-nacos-discovery-2.2.3.RELEASE.jar;D:\tools\m2\com\alibaba\nacos\nacos-client\1.3.3\nacos-client-1.3.3.jar;D:\tools\m2\com\alibaba\nacos\nacos-common\1.3.3\nacos-common-1.3.3.jar;D:\tools\m2\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\tools\m2\commons-io\commons-io\2.2\commons-io-2.2.jar;D:\tools\m2\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;D:\tools\m2\org\apache\httpcomponents\httpcore\4.4.14\httpcore-4.4.14.jar;D:\tools\m2\org\apache\httpcomponents\httpcore-nio\4.4.14\httpcore-nio-4.4.14.jar;D:\tools\m2\com\alibaba\nacos\nacos-api\1.3.3\nacos-api-1.3.3.jar;D:\tools\m2\org\apache\commons\commons-lang3\3.10\commons-lang3-3.10.jar;D:\tools\m2\com\google\guava\guava\24.1.1-jre\guava-24.1.1-jre.jar;D:\tools\m2\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;D:\tools\m2\org\checkerframework\checker-compat-qual\2.0.0\checker-compat-qual-2.0.0.jar;D:\tools\m2\com\google\errorprone\error_prone_annotations\2.1.3\error_prone_annotations-2.1.3.jar;D:\tools\m2\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;D:\tools\m2\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;D:\tools\m2\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;D:\tools\m2\com\fasterxml\jackson\core\jackson-core\2.11.4\jackson-core-2.11.4.jar;D:\tools\m2\io\prometheus\simpleclient\0.5.0\simpleclient-0.5.0.jar;D:\tools\m2\com\alibaba\spring\spring-context-support\1.0.10\spring-context-support-1.0.10.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-commons\2.2.5.RELEASE\spring-cloud-commons-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\security\spring-security-crypto\5.3.8.RELEASE\spring-security-crypto-5.3.8.RELEASE.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-context\2.2.5.RELEASE\spring-cloud-context-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.2.5.RELEASE\spring-cloud-starter-netflix-ribbon-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-starter\2.2.5.RELEASE\spring-cloud-starter-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\security\spring-security-rsa\1.0.9.RELEASE\spring-security-rsa-1.0.9.RELEASE.jar;D:\tools\m2\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;D:\tools\m2\org\bouncycastle\bcprov-jdk15on\1.64\bcprov-jdk15on-1.64.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.5.RELEASE\spring-cloud-netflix-ribbon-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.5.RELEASE\spring-cloud-netflix-archaius-2.2.5.RELEASE.jar;D:\tools\m2\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.5.RELEASE\spring-cloud-starter-netflix-archaius-2.2.5.RELEASE.jar;D:\tools\m2\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\tools\m2\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\tools\m2\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;D:\tools\m2\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;D:\tools\m2\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\tools\m2\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\tools\m2\com\netflix\hystrix\hystrix-core\1.4.3\hystrix-core-1.4.3.jar;D:\tools\m2\javax\inject\javax.inject\1\javax.inject-1.jar;D:\tools\m2\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\tools\m2\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;D:\tools\m2\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\tools\m2\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;D:\tools\m2\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\tools\m2\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;D:\tools\m2\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\tools\m2\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\tools\m2\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\tools\m2\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\tools\m2\com\netflix\servo\servo-core\0.10.1\servo-core-0.10.1.jar;D:\tools\m2\com\netflix\servo\servo-internal\0.10.1\servo-internal-0.10.1.jar;D:\tools\m2\com\netflix\netflix-commons\netflix-commons-util\0.1.1\netflix-commons-util-0.1.1.jar;D:\tools\m2\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;D:\tools\m2\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\tools\m2\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\tools\m2\org\springframework\boot\spring-boot-devtools\2.3.9.RELEASE\spring-boot-devtools-2.3.9.RELEASE.jar;D:\tools\m2\org\springframework\boot\spring-boot\2.3.9.RELEASE\spring-boot-2.3.9.RELEASE.jar;D:\tools\m2\org\springframework\boot\spring-boot-autoconfigure\2.3.9.RELEASE\spring-boot-autoconfigure-2.3.9.RELEASE.jar;D:\tools\m2\org\projectlombok\lombok\1.18.18\lombok-1.18.18.jar com.nacos.config.DemoNacosConfigApplication
2023-02-10 14:46:22.131  INFO 13212 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.9.RELEASE)

2023-02-10 14:46:23.420  INFO 13212 --- [  restartedMain] c.n.config.DemoNacosConfigApplication    : The following profiles are active: dev
2023-02-10 14:46:23.700  INFO 13212 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=d59d82fe-a1e4-3ce6-936a-2efb94c41cb5
2023-02-10 14:46:23.876  INFO 13212 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2023-02-10 14:46:23.880  INFO 13212 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-02-10 14:46:23.880  INFO 13212 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2023-02-10 14:46:23.915  INFO 13212 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-02-10 14:46:23.915  INFO 13212 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 485 ms
2023-02-10 14:46:23.933  WARN 13212 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoController': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'abc' in value "${abc}"
2023-02-10 14:46:23.934  INFO 13212 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-02-10 14:46:23.939  INFO 13212 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-02-10 14:46:23.944 ERROR 13212 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoController': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'abc' in value "${abc}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
	at com.nacos.config.DemoNacosConfigApplication.main(DemoNacosConfigApplication.java:13) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_351]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_351]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_351]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_351]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.9.RELEASE.jar:2.3.9.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'abc' in value "${abc}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	... 26 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'abc' in value "${abc}"
	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:918) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
	... 37 common frames omitted


Process finished with exit code 0

           

解决办法:在项目的pom文件中添加nacos的配置依赖

<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>2.2.3.RELEASE</version>
        </dependency>
           

再次运行效果,成功

SpringCloud alibaba使用Nacos读取变量报错 Could not resolve placeholder ‘xxx‘ in value “${xxx}“