gpt4 book ai didi

java - @ConditionalOnProperty on TYPE level w/@Configuration

转载 作者:行者123 更新时间:2023-11-29 04:23:26 25 4
gpt4 key购买 nike

是否可以在 TYPE 级别使用 @ConditionalOnProperty,以便它查看/评估非默认属性文件中定义的属性?

以下似乎仅当属性在默认属性文件中定义时才有效,即在 application.properties

@Configuration
@ConditionalOnProperty(prefix = "jmx.rmi", value = "enabled")
public class JmxConfiguration {
// JMX related stuff
}

最佳答案

@ConditionalOnPropertyorg.springframework.core.env.Environment bean 中提取数据。这取决于您如何填充它。您可以显式声明多个属性文件:

@PropertySources({
@PropertySource(name = "default", value = "classpath:application.properties"),
@PropertySource(name = "custom", value = "file:custom.properties", ignoreResourceNotFound = true)
})
public class SpringBootApplication {...}

并且这两个文件的内容将附加到 Environment

关于java - @ConditionalOnProperty on TYPE level w/@Configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47715543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com