配置文件错误了?

来源:4-1 项目属性配置知多少

伟大的爪哇程序员

2021-01-02 00:31

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


写回答 关注

1回答

  • 小羊爱主
    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;

    }


    }


2小时上手SpringBoot

2小时上手SpringBoot,实战开发红包表白程序,体现程序员专属花式浪漫

11882 学习 · 115 问题

查看课程

相似问题