Skip to content

"Failed to determine a suitable driver class" in Spring AOT #2006

@jeffawx

Description

@jeffawx

In my custom BeanFactoryInitializationAotProcessor class, if I use beanFactory.getBeansOfType to get a bean where this bean has dependency on repository interface, build fails throwing:

Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
        at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:186)
        at org.springframework.boot.autoconfigure.jdbc.PropertiesJdbcConnectionDetails.getDriverClassName(PropertiesJdbcConnectionDetails.java:49)
        at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:55)
        at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:117)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)

How to reproduce: checkout this repo: https://github.com/jeffawx/native-jdbc
Run: ./gradlew processAot should see error

I understand the bean context isn't fully initialised at this stage, but do we have some mechanism to force repository beans initialise properly before AOT processing happens?

Mark the repository as @Lazy fix the problem, but its a bit ugly, is there any proper way?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions