@conditionalonproperty在w/ configuration的类型级别上



是否可以在类型级别上使用 @ConditionalOnProperty,因此它可以看到/评估在非默认属性文件中定义的属性?

以下似乎仅在默认属性文件中定义属性时才能使用,即在 application.properties

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

@ConditionalOnProperty org.springframework.core.core.env.env.env.env.env.env.env.env.env.srironment bean提取数据。这取决于您如何填充它。您可以明确声明多个属性文件:

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

,两个文件的内容将附加到Environment

相关内容

最新更新