Home > Software design >  How to make Springboot disable/enable an hazelcast autoconfiguration based on config file
How to make Springboot disable/enable an hazelcast autoconfiguration based on config file

Time:08-13

Doing a Springboot app in which we can select between two different types of caches, HazelCast and Infinispan, this selection is done by passing enabled or disabled via a .yaml config file, that sets which profile Hazelcast or Infinispan, spring should take:

 hazelcast:
      enabled: false

But even with this option set to false, and the app going to the Infinispan profile, I still have to disable Hazelcast autoconfiguration on spring app main so that it doesn't use Hazelcast. My question is, is it possible to make the Springboot main read the file before launching the spring so that it disables Hazelcast auto-configuration if Hazelcast is disabled so that I don't have to disable it via annotation or properties file? Something like this

if Hazelcast is disabled disabled:

     exclude = { HazelcastAutoConfiguration.class}

CodePudding user response:

Try disabling autoconfiguration with a system property Eg.

-Dspring.autoconfigure.exclude=org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration

Or use spring.config.activate.on-profile to deactivate depending on the spring.profiles.active setting. Essentially multiple properties and you use the execution profile setting to select.

CodePudding user response:

Solved it by adding this to the infinispan profile config yaml that overrides the default config:

 spring:
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
  • Related