-
Notifications
You must be signed in to change notification settings - Fork 41.2k
@DataJpaTest using H2 with schema.sql and spring.datasource.schema-username fails #19321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is an edge case that we've not considered. You might be able to work around it by overriding the |
Currently, `jdbcUrl` is determined when `spring.datasource.schema-username` and `spring.datasource.schema-password` configuration properties are set. This behaviour causes an issue trying to perform sql scripts in the wrong database. This commit introduces to get the right `url` from the `dataSource` bean. See spring-projectsgh-19321
I have added my findings in #19327 (comment) |
Currently, `jdbcUrl` is determined when `spring.datasource.schema-username` and `spring.datasource.schema-password` configuration properties are set. This behaviour causes an issue trying to perform sql scripts in the wrong database. This commit introduces to get the right `url` from the `dataSource` bean. See spring-projectsgh-19321
Closing in favour of #19327. |
We're going to give it another go by overriding |
Can this be worked? |
The |
This appears to work, but I'd like some more eyes on it before merging it. |
@wilkinsona I haven't created a PR yet. will do so if you think its a viable fix. |
Thanks for the offer, @somayaj, but if the team agree that my proposed changes seem reasonable we won't need a PR for this one. |
LGTM Andy. Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Version: Spring Boot v2.2.1.RELEASE, Spring v5.2.1.RELEASE
Hi, I'm using
@DataJpaTest
with default embedded H2 DB for testing. Also I'm creating DB schema usingschema.sql
which containsCREATE SCHEMA IF NOT EXISTS TEST_SCHEMA;
.Unit tests annotated with the
@DataJpaTest
ran fine until I added to my productionapplication.properties
propertiesspring.datasource.schema-username=${DB_USERNAME_SCH}
andspring.datasource.schema-password=${DB_PASSWORD_SCH}
.This causes that a datasource based on the application.properties is trying to be created instead of the default H2 database. The creation of DB from application.properties fails because the datasource configuration looks like this:
I would expect that the embedded H2 is used even if the schema-username and schema-password is used.
Source code which caueses the problem:
org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java:197 which is called from org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java:101
The text was updated successfully, but these errors were encountered: