首页 文章

如何在spring boot中将值写入application.properties

提问于
浏览
1

我已经看过Write/Update properties file value in spring

在 Spring 季启动

如何在spring boot中将值写入application.properties?

application.properties:
ews.batch_type =
ews.batch_dat =
......其他领域

我想要:

application.properties:
ews.batch_type = ALL
ews.batch_dat = 20170222
......其他领域

谢谢

1 回答

  • 0

    在您提供更多信息后,我想您要定义默认值 . application.properties 仍然是静态的,但您可以在应用程序中执行某些操作来处理缺少的属性 .

    您可以定义默认值

    // Gets the Value of "ews.batch_type" or "ALL" if no property is defined
    @Value("${ews.batch_type:ALL}")
    private String batchType;
    
    public static String getDate() {
        return "..."; // <- the date you want
    }
    
    @Value("#{ config['ews.batch_dat'] ?: T(yourClass).getDate() }")
    private String date;
    

相关问题