是否可以在TYPE级别使用@ConditionalOnProperty
,以便查看/评估在非默认属性文件中定义的属性?
以下似乎仅在默认属性文件中定义属性时起作用,即在application.properties
@Configuration
@ConditionalOnProperty(prefix = "jmx.rmi", value = "enabled")
public class JmxConfiguration {
// JMX related stuff
}
答案 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