I want to auto-configure a @Service
only if Mongo was configured.
What's the appropriate way to do it?
My thought is to use:
@ConditionalOnBean(MongoTemplate.class)
Is there a better @Conditional
method I should use instead?
I want to auto-configure a @Service
only if Mongo was configured.
What's the appropriate way to do it?
My thought is to use:
@ConditionalOnBean(MongoTemplate.class)
Is there a better @Conditional
method I should use instead?
Yes, you can use Conditional on property having specific value. Here is simple annotation:
@ConditionalOnProperty(value = "database.type", havingValue = "MONGO", matchIfMissing = true)
You can use the annotation for all beans related with the specified DB for example or create config that is conditional on property