问题1. Cloud not resolve placeholder 'user.name' in value "${user.name}",无法注入。
问题2. java.lang.reflect.InvocationTargetException
解决方案:
在resources文件夹先创建bootstrap.properties文件,并配置
spring.application.name
spring.cloud.nacos.config.server-addr
#nacos配置中心文件命名格式 ${spring.application.name}-${spring.profile.active}.${spring.cloud.nacos.config.file-extension} #当spring.profile.active为空时文件命名格式为 ${spring.application.name}.${spring.cloud.nacos.config.file-extension}
<!--springboot版本号-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--配置中心-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--该依赖视情况而定,有的可能加不加都可以-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.1</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>