LoginSignup
0
0

More than 5 years have passed since last update.

Spring boot error types explained

Posted at

Spring Boot Error due to Starter Dependency

Some of my friends and readers got this error even if they don't need a Database. The main reason they were getting this error was because of starter dependency like some of they have included spring-boot-starter-data-jpa which then included hibernate-entitymanager.jar and they didn't have additional things need to set that up.

Sometimes including incorrect Starter POM can also solve this problem like adding spring-boot-starter-jdbc instead of spring-boot-starter-data-jpa dependency.

If you know, Spring Boot auto-configuration is triggered by JAR dependencies present in the classpath and if it pulls something which you don't need then this type of error can come.

That's why a good knowledge of Spring fundamentals are needed to use Spring boot correctly. If you are new into the Spring framework, I suggest you go through Learn Spring: The Certification Class by Eugen Paraschiv of Baeldung to learn Spring 5 and Spring Boot 2 from scratch, in a guided, code-focused way.

Due to Missing Dependency:

Sometimes you do need a database but you forgot to include the driver JAR file into the classpath, which can also cause this error. For example, you have specified the following properties in the application.properties, spring boots configuration file but didn't include the corresponding MySQL JDBC driver into the classpath

spring.datasource.url = jdbc:mysql://localhost/test
spring.datasource.driver-class-name= com.mysql.jdbc.Driver

In order to solve this error, either you need to include the correct Starter POM dependency or manually add the MySQL JDBC JAR file into the classpath. If you are interested, you can see this tutorial to learn more about how to connect a Java application to a database using a MySQL database in this tutorial.

Due to Missing Configuration in Application.properties

Spring Boot is good at configuring in-memory Databases like H2, HSQLDB, Derby, etc and it can configure them by just adding their JAR files into the classpath but for others, you need to give Spring Boot additional details like URL, DriverClass name, etc.

You can do that by adding some properties to application.properties file with the spring.datasource prefix, as shown in following example:

spring.datasource.url = jdbc:mysql://localhost/abc
spring.datasource.name=testme
spring.datasource.username=xxxx
spring.datasource.password=xxxx
spring.datasource.driver-class-name= com.mysql.jdbc.Driver spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

This will provide the Spring Boot auto-configuration component to configure the database for you. If you want to learn more about how auto-configuration works in Spring Boot, I suggest you go through a comprehensive Spring boot course like Spring Boot: Efficient Development, Configuration, and Deployment course on Pluralsight, which will also teach you the details behind @EnableAutoConfiguration by writing your own auto configurations.

Related blog:

Spring boot tutorial

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0