The first time I used springboot to do a project, this mistake is very simple, but it took me more than two hours to solve it.!!
1. According to the Convention, write a test class to test whether the connection to the database is successful
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.sql.DataSource;
@SpringBootTest
class SpringbootThymeleaf001ApplicationTests {
//Test database connection
@Autowired
DataSource dataSource;
@Test
void contextLoads() throws Exception{
System.out.println("The database connection obtained is :"+dataSource.getConnection());
}
}
The connection was tested at the beginning and the connection was successful. Then, when I started the project, there was an error, so I turned back and tested the connection again, and even reported an error!! Nothing changed in the middle!
2. Solutions
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
Replace the above dependency with the following dependency, successfully solved!
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
Read More:
- Springcloud builds a gateway and starts Error [Solved]
- spring cloud 2020 gateway Error 503 [How to Solve]
- How to Solve Spring integrate Seata startup error
- Caused by: java.lang.IllegalStateException (How to Fix)
- JUnit tests mybatis-plus error: null pointer [How to Solve]
- Error resolving template [index], template might not exist
- [Solved] SpringBoot Create Project and Failed to Access localhost:8080 Error
- [Solved] spring boot integrated PageHelper Error
- [Solved] Failed to start bean ‘eurekaAutoServiceRegistration‘; nested exception is java.lang.NullPointerExce
- [Solved] BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘
- [Solved] Spring Cloud Use Ribbon Error: No instances available for XXX
- [Solved] ‘build.plugins.plugin.version‘ for org.springframework.boot:spring-boot-maven-plugin is missing.
- Eureka Error: registration status: 204 deregister status: 200
- [Siolved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘webMvcObject
- How to Solve Swagger error: IllegalStateException
- [Solved] IDEA Start Maven Project Error: “Error starting ApplicationContext. To display the conditions report …”
- How to Solve idea com.baomidou Error
- [Solved] Classnotfoundexception: org.springframework.core.nativedetector error
- [Solved] Openfegn Remote Call Error: java.lang.NullPointerException: null
- [Solved] Mybatis add dependencies Error: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.