spring-boot
spring-boot copied to clipboard
DataSourceBeanCreationFailureAnalyzer should suggest adding 'spring.datasource.url' property
I've generated a spring boot project using https://start.spring.io/ with java, maven, spring boot 2.7.7. I did not add/change anything.
When adding PostgreSQL and spring-data-jpa (or spring-data-jdbc) I get the following when running mvn test
:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
When adding @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
to src/main/java/com/example/demo/DemoApplication.java the test runs fine
The expected behavior would be that a newly generated spring boot project tests and runs out-of-the-box (even if some further configurations are missing). Or at least the above infos "Consider the following..." should mention that one needs to set the driver
The expected behavior would be that a newly generated spring boot project tests and runs out-of-the-box (even if some further configurations are missing).
That won't work. The @SpringBootTest
starts your application as your main
method would do, and as you included the PostgreSQL driver, tries to bootstrap a datasource.
If you include an embedded database dependency (h2, HSQL or derby) then the tests would automatically reconfigure to use that.
Or at least the above infos "Consider the following..." should mention that one needs to set the driver
That i can agree to. The "Consider the following:" section could include a hint to spring.datasource.url
.
i used mySQL and i added the annotation that has been suggested up and still the system generating the same issue. i added question on stackoverflow but i did not get any answer
https://stackoverflow.com/questions/75520481/springboot-v4-4-17-2-mysql-failed-to-determine-a-suitable-driver-class
@mhalbritter I am also facing the same issue for a while now check lots of third party website including stack overflow, all I can say is the problem seems to be very inconsistent.
I have the code where I anyone could recreate the issue, should I send it.
@rabbanimdrb The problem described here is very consistent, and the steps to reproduce it have been provided. We've categorized this as a bug, as the Actions
from the failure analyzer should include setting the spring.datasource.url
property.
the problem seems to be very inconsistent
What makes you say that the problem is inconsistent?
@rabbanimdrb The problem described here is very consistent, and the steps to reproduce it have been provided. We've categorized this as a bug, as the
Actions
from the failure analyzer should include setting thespring.datasource.url
property.the problem seems to be very inconsistent
What makes you say that the problem is inconsistent?
What I meant to say is, the problem I encounter is not consistent, as I follow the exact same steps each time, yet it occurs occasionally, while there are instances when it does not appear at all.
English is not my first language, so please forgive any issues with my language proficiency.
@rabbanimdrb if you think you found a bug, please consider opening a new issue where you describe your problem and please also attach a sample with which we can reproduce the problem. Thanks!
That i can agree to. The "Consider the following:" section could include a hint to spring.datasource.url
It used to be this way and we removed it. This code path can be reused in custom code (typically to create multiple datasources) and hardcoding "our" prefix is going to break that.
Ah, thanks for the context @snicoll. I'll close this issue then.
https://github.com/spring-projects/spring-boot/issues/12947 is the issue where the specific mention of spring.datasource.url
was removed.
I wonder if there's some middle ground to be found here. Could we mention the url
property (without assuming a prefix) in the "Consider the following" section? I also wonder if we should use "property" rather than "attribute" in "'url' attribute is not specified".