nacos-spring-project icon indicating copy to clipboard operation
nacos-spring-project copied to clipboard

yaml list取不到值?

Open hello-zhengzq opened this issue 4 years ago • 7 comments

https://github.com/nacos-group/nacos-spring-project/issues/174#issue-538159586 请问这是用的是哪个项目sample,我用的nacos-spring-project,环境同issue里描述,启动时listv映射就报错了,其他正常能获取到值。 Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property 'listv[0]' of bean class [com.alibaba.nacos.example.spring.model.Promotion]: Cannot access indexed value of property referenced in indexed property path 'listv[0]': returned null

private Long sku;
private Double price;
private Integer amount;

@NacosProperty(value = "desc")
@JSONField(name = "desc")
private String description;

@NacosIgnore
private Integer sold;

private List<String> listv;


yml:
 sku: 2
 price: 99.9  
 amount: 1001  
 desc: "Hooray! It's snowing! 下雪了!"  
 description: descipt  
 sold: 100  
 listv:  
    - one  
    - two  

hello-zhengzq avatar Mar 27 '20 11:03 hello-zhengzq

这个代码完整的看下,整个应该用@NacosConfigurationOnProperties这个注解

chuntaojun avatar Mar 27 '20 11:03 chuntaojun

这个代码完整的看下,整个应该用@NacosConfigurationOnProperties这个注解

@NacosConfigurationProperties(dataId = "promotion.yml", groupId = "spring-example", autoRefreshed = true, type = ConfigType.YAML)
public class Promotion {

    private Long sku;

    private Double price;

    private Integer amount;

    @NacosProperty(value = "desc")
    @JSONField(name = "desc")
    private String description;

    @NacosIgnore
    private Integer sold;

    private List<String> listv;

    // getter and setter

hello-zhengzq avatar Mar 27 '20 12:03 hello-zhengzq

这个代码完整的看下,整个应该用@NacosConfigurationOnProperties这个注解

NacosConfigurationOnProperties?是哪个包里,用NacosConfigurationProperties不行

hello-zhengzq avatar Mar 29 '20 01:03 hello-zhengzq

没人遇到这个问题吗...QAQ

hello-zhengzq avatar Apr 08 '20 05:04 hello-zhengzq

没人遇到这个问题吗...QAQ

如果你用的是@NacosConfigurationProperties注解,设置ignoreNestedProperties=true

GoldyMark avatar Nov 25 '20 03:11 GoldyMark

没人遇到这个问题吗...QAQ

如果你用的是@NacosConfigurationProperties注解,设置ignoreNestedProperties=true

是的,已解决。

hello-zhengzq avatar Nov 26 '20 03:11 hello-zhengzq

请问相应组件的版本号是多少? SpringBoot:2.5.2 nacos-spring-context: 1.1.1/1.0.0/0.3.6 版本均无法注入,配置示例如下: image

image

https://github.com/nacos-group/nacos-spring-project/issues/284

yuxiao97 avatar Apr 21 '22 06:04 yuxiao97