Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConditionalOnMissingBean by name

I have multiple datasource beans defined in my configuration file.I have 2 beans named customerDataSource. I want one of them to be instantiated only if other bean is not loaded.I was trying to use @ConditionalOnMissingBean. However it looks like this will work only when another bean of same "type" is not present. Is there a way to control this by using "name"?

like image 227
Punter Vicky Avatar asked Sep 15 '25 19:09

Punter Vicky


1 Answers

The annotation has the parameter name, where you can specify the bean name that should be checked:

@ConditionalOnMissingBean(name = "beanNameToCheck")
like image 63
dunni Avatar answered Sep 18 '25 09:09

dunni