2

I create :

  • one library using Spring (common-spring)
  • one springboot project which use this library.

In my library common-spring, I have create multiple HealthIndicator (Actuator).

In my HealhIndicator I define the @ConditionalOnEnabledHealthIndicator

@ConditionalOnEnabledHealthIndicator("mailServiceIndicator")
@Component
public class MailServiceHealthIndicator implements HealthIndicator

I would like to indicate that all these Indicator are disabled by default. So, I add in my library application.properties :

management.health.mailServiceIndicator.enabled=false

My problem is : this properties is not take account when I run my springboot application. It's seem that the application.properties of my library is not use.

I try to change the name of my libray application.properties to common-spring.properties and add in a @Configuration class :

@PropertySource({
        "classpath:common-spring.properties",
        "classpath:application.properties"
})

But that no change the behavior. (When I do that and I read the propertySource, properties from library are well found but not use in my Indicator in the library)

If I was clear, does anyone have any idea how to get my libraria to use the application.properties?

Thanks

tgallei
  • 827
  • 3
  • 13
  • 22
schwuleur
  • 41
  • 2
  • 1
    Only one `application.properties` will be read, the one that is first on the classpath (which will always be the on in the application **not** the one in your. Using `@PropertySource` won't work as that hasn't been processed when doing the `@Conditional` checks. Instead of specifing defaults in your file, hardcode them in your condition (if properry not available assume `false` else use value from property). No need to mess around with an additional file etc. – M. Deinum May 16 '22 at 13:43
  • Thanks for the response. Ok but how do you do to put a value false if property is not know in the : ConditionalOnEnabledHealthIndicator ? – schwuleur May 16 '22 at 13:59
  • You don't you just return `false` for the `Condition`. – M. Deinum May 16 '22 at 14:01

0 Answers0