【发布时间】:2020-09-16 07:14:36
【问题描述】:
所以我有一些自定义 POJO。当我通过空构造函数实例化该对象时,我希望随时将其归档的fee 初始化为来自application.properties 的某个预设值。
在我的application-prod.properties:
fee=1500
我的 POJO 类:
public class PenaltyWithNoInvoiceDto {
private int penatltyId;
private int number;
private String projectName;
@Value("${fee}")
private float fee;
public PenaltyWithNoInvoiceDto() {
}
public PenaltyWithNoInvoiceDto(int penatltyId, int number, String projectName) {
super();
this.penatltyId = penatltyId;
this.number = number;
this.projectName = projectName;
}
}
在我的@Service 类中,我使用空构造函数实例化PenaltyWithNoInvoiceDto。但是当我打印fee 字段时,我得到了零。
如何使该字段的值为 1500,我从 application-prod.properties 获得该值?
【问题讨论】:
-
您必须使用 prod 配置文件启动您的应用程序。 stackoverflow.com/questions/40060989/…
标签: spring-boot environment-variables