1

Is it possible to use @ConditionalOnProperty on TYPE level so it sees/evaluates properties defined in non-default properties files?

Following seems to work only when the property is defined in the default properties file, i.e. in application.properties

@Configuration
@ConditionalOnProperty(prefix = "jmx.rmi", value = "enabled")
public class JmxConfiguration {
    // JMX related stuff
}
Jaroslav Záruba
  • 4,694
  • 5
  • 39
  • 58

1 Answers1

6

@ConditionalOnProperty extracts data from org.springframework.core.env.Environment bean. It depends on you how you do populate it. You can explicitly declare multiple properties files:

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

And the content of both files will be appended to Environment

Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42