question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database Init fails after upgrade to Spring Boot 2.4.x

See original GitHub issue

After upgrading from Spring boot 2.3.5.RELEASE to 2.4.x our application cannot initialise the database connection using Exposed anymore. The full stack trace is attached below.

The piece of code where the exceptions happens:

    @Bean
    fun initDatabase(dataSource: DataSource): Database {
        val connect = Database.connect(dataSource)
        transaction {
            SchemaUtils.create(
                OrderTable,
               ***REDACTED***
            )
        }
        return connect
    }

The datasource injected in this function is just a datasource with username, password and URL of type MariaDbPoolDataSource where the URL is: jdbc:mariadb:aurora://***REDACTED***-***REDACTED***.cluster-***REDACTED***.eu-west-1.rds.amazonaws.com:3306/***REDACTED***?connectTimeout=60000&minPoolSize=0&maxIdleTime=60

Any ideas what is going on?

Full stack trace:

2021-05-10 17:31:07.649 ERROR 80020 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initDatabase' defined in class path resource [net/***REDACTED***/adapters/exposed/ExposedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jetbrains.exposed.sql.Database]: Factory method 'initDatabase' threw exception; nested exception is java.sql.SQLSyntaxErrorException: No connection available within the specified time (option 'connectTimeout': 60,000 ms)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
	at net.***REDACTED***.Application$Companion.main(Application.kt:107)
	at net.***REDACTED***.Application.main(Application.kt)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jetbrains.exposed.sql.Database]: Factory method 'initDatabase' threw exception; nested exception is java.sql.SQLSyntaxErrorException: No connection available within the specified time (option 'connectTimeout': 60,000 ms)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 21 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: No connection available within the specified time (option 'connectTimeout': 60,000 ms)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:62)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:153)
	at org.mariadb.jdbc.MariaDbPoolDataSource.getConnection(MariaDbPoolDataSource.java:239)
	at org.jetbrains.exposed.sql.Database$Companion$connect$3.invoke(Database.kt:123)
	at org.jetbrains.exposed.sql.Database$Companion$connect$3.invoke(Database.kt:58)
	at org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:112)
	at org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:58)
	at org.jetbrains.exposed.sql.Database.metadata$exposed_core(Database.kt:22)
	at org.jetbrains.exposed.sql.Database$vendor$2.invoke(Database.kt:34)
	at org.jetbrains.exposed.sql.Database$vendor$2.invoke(Database.kt:15)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at org.jetbrains.exposed.sql.Database.getVendor(Database.kt)
	at org.jetbrains.exposed.sql.Database$Companion.getDefaultIsolationLevel(Database.kt:164)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager.getDefaultIsolationLevel(ThreadLocalTransactionManager.kt:20)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:121)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:120)
	at net.***REDACTED***.adapters.exposed.ExposedConfiguration.initDatabase(ExposedConfiguration.kt:67)
	at net.***REDACTED***.adapters.exposed.ExposedConfiguration$$EnhancerBySpringCGLIB$$a0c274d1.CGLIB$initDatabase$1(<generated>)
	at net.***REDACTED***.adapters.exposed.ExposedConfiguration$$EnhancerBySpringCGLIB$$a0c274d1$$FastClassBySpringCGLIB$$d1c65d13.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at net.***REDACTED***.adapters.exposed.ExposedConfiguration$$EnhancerBySpringCGLIB$$a0c274d1.initDatabase(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 22 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: No connection available within the specified time (option 'connectTimeout': 60,000 ms)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:62)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:171)
	at org.mariadb.jdbc.internal.util.pool.Pool.getConnection(Pool.java:413)
	at org.mariadb.jdbc.MariaDbPoolDataSource.getConnection(MariaDbPoolDataSource.java:237)
	... 46 common frames omitted

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benjaminkomencommented, Jun 11, 2021

Thanks for your help @Tapac , I’m going to close this issue, as it has been resolved for me.

0reactions
benjaminkomencommented, Jun 11, 2021

Interesting, with Exposed 0.32.1 and with spring boot 2.5.1 it does seem to work! But what has changed, I wonder…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot 2.4.4 failed to start after upgrading - Stack Overflow
You are defining a lot of versions on your own (you should not), also using old dependencies that are not available anymore (fyi:...
Read more >
Config file processing in Spring Boot 2.4
1, some unit-tests started to fail, as they began to ignore src/test/resources/application.properties and use content from src/main/resources/ ...
Read more >
Book's Code Upgrade: Migrate from Spring Boot 2.3 to 2.4
Step-by-step migration guide from Spring Boot 2.3 to Spring Boot 2.4 ... database files, you'll get this error during the initialization of ...
Read more >
Spring Boot, Maven and Eclipse Errors and TroubleShooting ...
Approach 1 : Spring Boot Project; Approach 2: Non Spring Boot Project. Error : On Maven > Update Project, Java 1.4 is auto...
Read more >
Bean Initialization on condition fails after Spring boot version ...
Coding example for the question Bean Initialization on condition fails after Spring boot version update to 2.0.1.Release-Springboot.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found