After upgrade to Spring Boot 2.5 a java.lang.ClassCastException
is raised during application initialization:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.ClassCastException: org.springframework.boot.jta.atomikos.AtomikosDataSourceBean cannot be cast to org.springframework.jdbc.datasource.SimpleDriverDataSource
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 104 common frames omitted
Caused by: java.lang.ClassCastException: org.springframework.boot.jta.atomikos.AtomikosDataSourceBean cannot be cast to org.springframework.jdbc.datasource.SimpleDriverDataSource
at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperty.get(DataSourceBuilder.java:442)
at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperties.get(DataSourceBuilder.java:339)
at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:183)
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.getMigrationDataSource(FlywayAutoConfiguration.java:149)
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.configureDataSource(FlywayAutoConfiguration.java:130)
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 105 common frames omitted
The Spring Boot configuration for the datasource is:
spring:
datasource:
password: passw0rd
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
flyway:
locations:
- classpath:db/migration/{vendor}
- classpath:db/migration/common
password: passw0rd
user: postgres
As a workaround I need to set the url
explicitly and the application starts successfully:
spring:
flyway:
url: ${spring.datasource.url}
Comment From: oridool
Seems like it is the same issue as with Liquibase:
26662
Comment From: snicoll
Indeed although it's more of a generic change/harmonization that is mentioned in the release notes and the logic needs to be refined.