Skip to content

Flyway-specific DataSource cannot be created in a native image due to missing reflection hints #33692

@mishraomp

Description

@mishraomp

Hi Team,
could anyone please look into this and let me know the workaround for the issue? or if there is a fix planned for this one.
Spring Boot Version: 3.0.1
Sample GitHub Repo:- https://github.com/mishraomp/spring-reactive
On JVM mode the app starts fine but in native mode it throws exception during startup. I have pasted the log outputs for the same.

JVM mode

2023-01-04T14:59:14.678-08:00  INFO 20988 --- [           main] com.om.example.SbReactiveApplication     : Starting SbReactiveApplication using Java 17 with PID 20988 (C:\projects\personal\spring-reactive\target\classes started by ompra in C:\projects\personal\spring-reactive)
2023-01-04T14:59:14.681-08:00  INFO 20988 --- [           main] com.om.example.SbReactiveApplication     : No active profile set, falling back to 1 default profile: "default"
2023-01-04T14:59:15.231-08:00  INFO 20988 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2023-01-04T14:59:15.331-08:00  INFO 20988 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 96 ms. Found 1 R2DBC repository interfaces.
2023-01-04T14:59:16.958-08:00  INFO 20988 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 14 endpoint(s) beneath base path ''
2023-01-04T14:59:17.189-08:00  INFO 20988 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 9.5.1 by Redgate
2023-01-04T14:59:17.189-08:00  INFO 20988 --- [           main] o.f.c.internal.license.VersionPrinter    : See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.5.1
2023-01-04T14:59:17.190-08:00  INFO 20988 --- [           main] o.f.c.internal.license.VersionPrinter    :
2023-01-04T14:59:17.468-08:00  INFO 20988 --- [           main] o.f.c.i.database.base.BaseDatabaseType   : Database: jdbc:postgresql://localhost:5432/default (PostgreSQL 15.1)
2023-01-04T14:59:17.518-08:00  INFO 20988 --- [           main] o.f.core.internal.command.DbValidate     : Successfully validated 1 migration (execution time 00:00.020s)
2023-01-04T14:59:17.547-08:00  INFO 20988 --- [           main] o.f.c.i.s.JdbcTableSchemaHistory         : Creating Schema History table "public"."flyway_schema_history" ...
2023-01-04T14:59:17.645-08:00  INFO 20988 --- [           main] o.f.core.internal.command.DbMigrate      : Current version of schema "public": << Empty Schema >>
2023-01-04T14:59:17.659-08:00  INFO 20988 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "public" to version "1.0.0 - API"
2023-01-04T14:59:17.711-08:00  INFO 20988 --- [           main] o.f.core.internal.command.DbMigrate      : Successfully applied 1 migration to schema "public", now at version v1.0.0 (execution time 00:00.079s)
2023-01-04T14:59:18.023-08:00  INFO 20988 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 3000
2023-01-04T14:59:18.043-08:00  INFO 20988 --- [           main] com.om.example.SbReactiveApplication     : Started SbReactiveApplication in 3.78 seconds (process running for 4.213)

Native Mode

2023-01-04 14:54:47  :: Spring Boot ::                (v3.0.1)
2023-01-04 14:54:47 
2023-01-04 14:54:47 2023-01-04T22:54:47.534Z  INFO 1 --- [           main] com.om.example.SbReactiveApplication     : Starting AOT-processed SbReactiveApplication using Java 17.0.5 with PID 1 (/workspace/com.om.example.SbReactiveApplication started by cnb in /workspace)
2023-01-04 14:54:47 2023-01-04T22:54:47.534Z  INFO 1 --- [           main] com.om.example.SbReactiveApplication     : No active profile set, falling back to 1 default profile: "default"
2023-01-04 14:54:47 2023-01-04T22:54:47.637Z  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 14 endpoint(s) beneath base path ''
2023-01-04 14:54:47 2023-01-04T22:54:47.672Z  WARN 1 --- [           main] .r.c.ReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway': Unexpected exception during bean creation
2023-01-04 14:54:47 2023-01-04T22:54:47.673Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
2023-01-04 14:54:47 
2023-01-04 14:54:47 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway': Unexpected exception during bean creation
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:534) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at com.om.example.SbReactiveApplication.main(SbReactiveApplication.java:21) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jdbc.datasource.SimpleDriverDataSource]: No default constructor found
2023-01-04 14:54:47     at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:146) ~[na:na]
2023-01-04 14:54:47     at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:175) ~[com.om.example.SbReactiveApplication:3.0.1]
2023-01-04 14:54:47     at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.getMigrationDataSource(FlywayAutoConfiguration.java:162) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47     at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.configureDataSource(FlywayAutoConfiguration.java:149) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47     at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:138) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47     at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration__BeanDefinitions$FlywayConfiguration__BeanDefinitions.lambda$getFlywayInstanceSupplier$0(FlywayAutoConfiguration__BeanDefinitions.java:99) ~[na:na]
2023-01-04 14:54:47     at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:68) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:54) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.aot.BeanInstanceSupplier.lambda$get$2(BeanInstanceSupplier.java:208) ~[na:na]
2023-01-04 14:54:47     at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:59) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:47) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.aot.BeanInstanceSupplier.invokeBeanSupplier(BeanInstanceSupplier.java:220) ~[na:na]
2023-01-04 14:54:47     at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:208) ~[na:na]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainInstanceFromSupplier(AbstractAutowireCapableBeanFactory.java:1225) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1210) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1157) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[com.om.example.SbReactiveApplication:6.0.3]
2023-01-04 14:54:47     ... 14 common frames omitted
2023-01-04 14:54:47 Caused by: java.lang.NoSuchMethodException: org.springframework.jdbc.datasource.SimpleDriverDataSource.<init>()
2023-01-04 14:54:47     at java.base@17.0.5/java.lang.Class.getConstructor0(DynamicHub.java:3585) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47     at java.base@17.0.5/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754) ~[com.om.example.SbReactiveApplication:na]
2023-01-04 14:54:47     at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) ~[na:na]
2023-01-04 14:54:47     ... 31 common frames omitted
2023-01-04 14:54:47

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions