I’ve got a spring-boot 3 project which uses a special DataSource configuration for the tests:
@Configuration
class DatabaseTestConfig extends AbstractJdbcConfiguration {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
DataSource getDataSource() {
return new EmbeddedDatabaseBuilder()
.setName("test")
.setType(H2)
.setScriptEncoding("UTF-8")
.ignoreFailedDrops(true)
.continueOnError(true)
.addScript("/h2/dump.sql")
.build();
}
}
At the commandline and IDE it works as expected, but in github-action the dump file can’t be found. Total path of the file: src/test/resources/h2/dump.sql
Relevant part of the workflow:
mvn-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17 for x64
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
architecture: x64
cache: maven
- name: Build with Maven
run: mvn verify
Part of the worflow log:
09:58:10.217 [ForkJoinPool-1-worker-1] DEBUG o.s.jdbc.datasource.SimpleDriverDataSource - Creating new JDBC Driver Connection to [jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false]
09:58:10.611 [ForkJoinPool-1-worker-1] DEBUG o.springframework.jdbc.datasource.init.ScriptUtils - Executing SQL script from class path resource [h2/dump.sql]
.
.
.
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'h2Console' defined in class path resource [org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.class]: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'h2Console' threw exception with message: Error creating bean with name 'getDataSource' defined in class path resource [codes/thischwa/dyndrest/DatabaseTestConfig.class]: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception with message: Cannot read SQL script from class path resource [h2/dump.sql]
Is there anybody who has a hint for me?