Issue
When developers have their own way to set up the Datasource, instead of using spring.datasource.xxxx, the spring boot application would fail at start.
I don't feel this is the right thing for spring boot to do. It supposed to be trying to help automate some setups by convention. This should be on best effort basis, It's good if spring boot could save developers' time from those boilerplates coding, however, it should never fail the application if it couldn't help setting up anything.
Tactical
I have seen a lot times we need to exclude DataSourceAutoConfiguration from @ComponentScanning manullay.
Solution
I think the best solution is probably to add a second/retry auto configuration after the user configuration. For the DataSourceAutoConfiguration, it would then able to figure out it doesn't satisfy the condition:
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java#L72
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java#L82
In terms of short term, I think the DataSourceAutoConfiguration class should be updated at least that it doesn't fail the application.
Comment From: wilkinsona
DataSourceAutoConfiguration should back off automatically if you define your own DataSource bean. It sounds like that may not be happening in your case but you haven't provided enough information for us to be certain. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: 1zg12
hi @wilkinsona , these are how our current project look like at a minimal:
https://github.com/1zg12/spring-boot-datasource-sample (the parent project to load in the library which has datasource configured) https://github.com/1zg12/spring-boot-datasource (the library project which provides the datasource auto configured)
Somehow the above projects worked. So I might be barking at the wrong tree that it could be our real parent/library project which has some issue within itself.
I will investigate further into that and post back if otherwise. Apologies for making a possible false alarm here.
Comment From: wilkinsona
No worries. Thanks for letting us know.