Springboot error: property ‘sqlsessionfactory’ or ‘sqlsessiontemplate’ are required error details

problem 1

is in the Mapper layer and it needs to be annotated with @mapper, but then someone put @respository online and it gets mixed up and it could be either one. It’s always going to be @mapper. Add the annotations, but if the Mapper layer in the configuration main class SpringBootMybatisApplication inside there is no need for @ MapperScan (” com. Example. Demo. Mapper “) scans annotations, add scan to the configuration class notes mean under this package all annotations into Mapper.

problem 2

SpringBoot project created with STS, where the configuration file defaults to application.properties, where the data source is typically configured. But want to play this file, you must add @ EnableAutoConfiguration to configure the main class (exclude = {DataSourceAutoConfiguration. Class}) automatic injection, otherwise the configuration in the configuration file is invalid. Failed to configure a DataSource: ‘URL’ attribute is not specified and no embedded DataSource could be configured. Error

but if this annotation is added at this time,

is dependent on the jar package in Mybatis

	<version>1.3.2</ version>

problem three

Automatic injection of SqlSessionFactory and SqlSessionTemplate is cancelled in

mybatis spring-1.3.2, so Property ‘SqlSessionFactory’ or ‘SqlSessionTemplate’ are required error will be reported.
you need to find a solution, so search the web for a solution, refer to this article, create a base class, and then let your dao inherit.


but my Mapper layer is using the annotated version of Mybatis, which is an interface and cannot inherit classes. So that’s not going to work.
since auto injection was eliminated in mybatis spring-1.3.2, I switched to a lower version of mybatis spring-1.1.1, but the fact remains the same, nothing has changed.

it is to find a way to don’t @ EnableAutoConfiguration (exclude = {DataSourceAutoConfiguration. Class}) automatic injection, so must the application. The properties to the application configuration file. The yml. The problem was finally solved.

Read More: