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:
- Cannot resolve reference to bean ‘sqlSessionFactory‘ while setting bean property ‘sqlSessionFactory‘
- [Solved] SpringBoot Create Project and Failed to Access localhost:8080 Error
- Spring Security Upgrade to Version 5.5.7, 5.6.4 or Above to Startup Error (Version incompatibility)
- How to Solve Springboot YML configurate logging.level error
- Springboot startup error: Field elasticsearchRestTemplate in cn.lili.modules.material.serviceImpl.QrMaterialServiceImpl required a bean of type
- SpringBoot—Error starting ApplicationContext. To display the auto-configuration report re-run your a
- [Solved] IDEA Start Maven Project Error: “Error starting ApplicationContext. To display the conditions report …”
- [Solved] SpringBoot Error: Property ‘mapperLocations‘ was not specified.
- Springboot Project: How to Introduces Local Jar Package
- When the database table field is set to self incrementing, use the entity class to insert or update the data to solve the error (Hibernate Framework)
- Error starting ApplicationContext. To display the conditions report re-run your application with ‘de
- How to Solve ERROR: Java 1.7 or later is required to run Apache Drill
- H2 memory database Oracle mode page error: rg.springframework.dao.InvalidDataAccessResourceUsageException: could not prepar
- Error querying database.Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource.
- How to Solve Springboot configurate environment file Error
- [Solved] SpringBoot Error: This application has no explicit mapping for /error,so you are seeing this as a fallback
- [Solved] Springboot Project Startup Error: Unable to Identify bootstrap.yml Configuration
- [Solved] SpringBoot Project Startup Error: Field userMapper in com.demo.controller.MemberController required a bean of type ‘c
- [Solved] SpringBoot Pack Project: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
- [Solved] Springboot integrate swagger error: Failed to start bean ‘documentationPluginsBootstrapper‘