CodexBloom - Programming Q&A Platform

Spring Boot Application scenarios to Start on JDK 21 with 'BeanCreationException' for DataSource

👀 Views: 69 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
spring-boot jdk-21 mysql datasource Java

I'm experiencing an scenario with my Spring Boot application that fails to start when I run it on JDK 21. The behavior message I'm seeing is `org.springframework.beans.factory.BeanCreationException: behavior creating bean with name 'dataSource': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.DataSourceUtils$TransactionException: Could not open JDBC Connection`. I've ensured that my `application.properties` file has the correct database URL, username, and password. Here are the relevant entries: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=secret spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver ``` I've also added the MySQL connector dependency in my `pom.xml`: ```xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.29</version> </dependency> ``` I initially thought that maybe the driver is not compatible with JDK 21, so I checked and it appears that version 8.0.29 should support newer JDKs. I've tried switching to version 8.0.30, but that didn't help either. Additionally, I've verified that my database is up and running and accessible, as I can connect using a database client. I also tried adding `spring.datasource.initialization-mode=always` to force initialization, but it made no difference. Could this scenario stem from any compatibility issues with Spring Boot and JDK 21, or is there something else I might be missing? Any insight would be greatly appreciated!