【问题标题】:Load @configuration based on property in spring boot在spring boot中根据属性加载@configuration
【发布时间】:2022-01-14 01:06:00
【问题描述】:

我正在学习 Spring Batch,并尝试根据某些属性加载作业配置。这可能吗,我们可以根据某些属性加载@Configuration 类吗?如果是,如何实现?

【问题讨论】:

    标签: spring-boot spring-batch


    【解决方案1】:

    是的,您只需要在您的@Configuration 类中使用@ConditionalOnProperty,如下所示:

    @Configuration
    @ConditionalOnProperty(name = {"your-property-name"}, havingValue = "true")
    public class ConditionalConfiguration {}
    

    您可以在以下在线资源中找到更多信息:

    【讨论】:

      猜你喜欢
      • 2014-12-21
      • 2021-12-15
      • 2020-05-03
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 2019-10-18
      • 2012-05-19
      相关资源
      最近更新 更多