Well, you're trying to do something that doesn't map well to spring boot in this form.
I suggest to slightly change the requirement:
Instead of trying to access the database in the custom condition, create a custom source of configuration and load the property from the database into the Environment so that when the conditionals get evaluated later on during the startup process, the property with an associated value (previously resolved from the database) is already available.
Examples of following such an approach are:
- Spring boot cloud config that reads the configuration properties from "remote" config service (via REST)
- Spring boot consul integration (that reads from consul obviously)
This approach is much more spring-friendly, and also has can save the application from calling the database multiple times (what if you have 100 beans with this custom conditional) - will it do 100 queries?
Now, this will mean probably that you won't need a custom conditional - probably it will be @Condition
on property.
Another caveat is that you won't be able to use JPA/Spring Data to load this property, probably you'll have to go with a Plain JDBC here.