【问题标题】:Can I define an application.properties file value as optional我可以将 application.properties 文件值定义为可选吗
【发布时间】:2019-09-26 09:40:48
【问题描述】:

在我的 application.properties 文件中,我想要一个可选值。如 spring.datasource.url=${value} 但可选 这可能吗?

【问题讨论】:

    标签: spring-boot properties


    【解决方案1】:

    您可以将属性定义为“可选”,方法是在注入时为其指定默认值。

    例如:

    @Value("${spring.datasource.url:null}")
    private String springDatasourceURL;
    

    【讨论】:

    • 据我所知,没有。
    • 看看这个:stackoverflow.com/questions/2513484/…这可能是你想要的。
    • 基于该问题,看起来默认值也可以在 xml 配置中设置。
    • 如果 2513484 回答了您的问题,请取消选中正确答案,我们可以将其标记为重复。
    猜你喜欢
    • 2012-06-29
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多