Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all Spring Boot datasources?

How can I list all Spring Boot datasources? Including ones that configured with Spring Cloud Config and others that autoconfigured being based on Maven dependencies of db drivers in pom.xml

like image 838
ieXcept Avatar asked Oct 19 '25 14:10

ieXcept


1 Answers

Assuming you have multiple datasources with different qualifiers , you can get it in a list. In fact not just for Datasource type , to list of any type , you can have similar code. and this list will have all bean implementations.

@Autowired
List<DataSource> datasources;

Or you can access by bean name as well.

@Autowired
Map<String,DataSource> datasources;
like image 100
surya Avatar answered Oct 21 '25 07:10

surya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!