TYPE级别的@ConditionalOnProperty w / @Configuration

时间:2017-12-08 13:39:43

标签: java spring

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

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

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

1 个答案:

答案 0 :(得分:2)

@ConditionalOnProperty org.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