可以跑通的版本如下
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.1</version>
</dependency>
@NacosValue(value = "${user1.name}",autoRefreshed = true)
public String name;
@NacosValue(value = "${user1.pwd}",autoRefreshed = true)
public int pwd;
@SpringBootApplication
@NacosPropertySource(dataId = "example", autoRefreshed = true)
public class NacostestApplication {
public static void main(String[] args) {
SpringApplication.run(NacostestApplication.class, args);
}
}
//在application.properties中配置注册中心的地址
nacos.config.server-addr=127.0.0.1:8848