Evaluating spring @value annotation as primitive boolean

后端 未结 4 733
情歌与酒
情歌与酒 2020-12-05 17:47

I have a spring @configuration annotated class MappingsClientConfig with a boolean field as:

 @Value(\"${mappings.enabled:true}\")
    private boolean mappi         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 18:50

    Its an old thread but if you still want to inject Non-String values using @Value Spring annotation, do this:

    @Value("#{new Boolean('${item.priceFactor}')}")
    private Boolean itemFactorBoolean;
    
    @Value("#{new Integer('${item.priceFactor}')}")
    private Integer itemFactorInteger;
    

    Works for me on Spring boot 1.5.9 with Java 8.

提交回复
热议问题