Tag Archives: XXX are required error

Springboot uses Oracle database to report property ‘sqlsessionfactory’ or ‘sqlsessiontemplate’ are required

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>