问答详情
源自:4-1 项目属性配置知多少

配置文件错误了?

Failed to bind properties under 'limit.description' to java.math.BigDecimal:


    Property: limit.description

    Value: 最少发${limit.minMoney}元红包,最多发${limit.maxMoney}元红包

    Origin: class path resource [application.yml] - 4:16

    Reason: failed to convert java.lang.String to java.math.BigDecimal


Action:


Update your application's configuration


提问者:伟大的爪哇程序员 2021-01-02 00:31

个回答

  • 小羊爱主
    2021-02-15 16:41:41

    //注意description是字符串,不是BigDecimal

    package com.imooc.luckymoney;

    import java.math.BigDecimal;

    import org.springframework.beans.factory.annotation.Value;

    import org.springframework.boot.context.properties.ConfigurationProperties;

    import org.springframework.stereotype.Component;


    @Component

    @ConfigurationProperties(prefix = "limit")

    public class LimitConfig {

    private BigDecimal minMoney;

    private BigDecimal maxMoney;

    private String description;

    public BigDecimal getMinMoney() {

    return minMoney;

    }

    public void setMinMoney(BigDecimal minMoney) {

    this.minMoney = minMoney;

    }

    public BigDecimal getMaxMoney() {

    return maxMoney;

    }

    public void setMaxMoney(BigDecimal maxMoney) {

    this.maxMoney = maxMoney;

    }

    public String getDescription() {

    return description;

    }

    public void setDescription(String description) {

    this.description = description;

    }


    }