Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required Spring Boot报错 java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required以及Error creating bean with name 'xxxMapper' defined in filexxx

Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
Spring Boot报错 java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required以及Error creating bean with name 'xxxMapper' defined in filexxx

搭建了一个简单的springboot项目,引了web、mysql、mybatis和mybatis-generator-core依赖,启动项目报错如下

Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
Spring Boot报错 java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required以及Error creating bean with name 'xxxMapper' defined in filexxxProperty ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
Spring Boot报错 java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required以及Error creating bean with name 'xxxMapper' defined in filexxx

解决方法:springboot启动类的@SpringBootApplication注解去掉

exclude= {DataSourceAutoConfiguration.class}

Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
Spring Boot报错 java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required以及Error creating bean with name 'xxxMapper' defined in filexxx

分析:参考了https://blog.****.net/jinru****/article/details/106539916,禁止 SpringBoot 自动注入数据源配置,DataSourceAutoConfiguration.class 会自动查找 application.yml 或者 properties 文件里的 spring.datasource.* 相关属性并自动配置单数据源「注意这里提到的单数据源」。如果项目中禁止自动注入数据源配置,又没有手动配置数据源(@ConfigurationProperties(prefix = "spring.datasource.hikari")

),启动就会报错,去掉这句就可以启动啦!

转载于:https://blog.****.net/qq_20210951/article/details/109309141