nacos-group / nacos-spring-project

Nacos ECO Project for Spring Framework
https://nacos.io/
Apache License 2.0
755 stars 310 forks source link

@NacosConfigurationProperties无法注入yaml配置 #284

Open yuxiao97 opened 2 years ago

yuxiao97 commented 2 years ago

Issue Description

如题,使用@NacosConfigurationProperties将配置注入到POJO类时,无法注入相关值。 Type: bug report or feature request

相关组件版本如下:

SpringBoot: 2.5.2

<dependency>
    <groupId>com.alibaba.nacos</groupId>
    <artifactId>nacos-spring-context</artifactId>
    <version>1.1.1</version>
</dependency>

Describe what happened (or what feature you want)

Config Class如下:

@Data
@Configuration
@NacosConfigurationProperties(prefix = "simple", autoRefreshed=true, type = ConfigType.YAML, ignoreNestedProperties = true,
        dataId = "${nacos.config.dataId}", groupId = "${nacos.config.groupId}")
public class SimpleObjConfig {

    private String name;

    private String school;

    private Integer age;

}

yaml配置如下: image

@NacosConfigurationProperteis注入效果如下: image

Describe what you expected to happen

使用@NacosConfigurationiProperties能正确注入相关配置的值,并且在配置中心修改后,Config Bean中的值是可以动态改变的。

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

itming001 commented 2 weeks ago

这个解决了吗 我也碰到同样的问题了