Exception Stacktrace:
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
ERROR 5614 --- [main] o.s.boot.SpringApplication : Application run failed
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource'
threw exception with message: Cannot load driver class: com.mysql.cj.jdbc.Driver
Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver
If you get this above exception when you try to run a Spring Boot application, the reason for this is that you have missed adding the dependency for MySQL driver.
gradle.build
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Maven: pom.xml
<dependencies>
<!-- Other dependencies -->
<!-- MySQL Connector/J as a runtime-only dependency -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- How to Find the Location of Notepad on Windows 11 - Windows
- Fix: FileNotFoundError: [Errno 2] No such file or directory: Python - Python
- How to Remove Widgets from macOS Sonoma 14 Desktop - MacOS
- Java 7 addSuppression() and getSuppression() Exception Handling - Java
- SharePoint 2016 error - Could not find file ManageUserProfileServiceApplicationTenantSimplified.xml - SharePoint
- Android: Save Data in local Db using Android Room - Android
- Integrating Android Facebook SDK 3.17.2 Tutorial - Android
- Android Parsing Data for android-L failed Unsupported major.minor version 51.0 Error - Android