当前位置: 代码迷 >> 综合 >> Springboot+Mybatis整合启动报Property sqlSessionFactory or sqlSessionTemplate are required
  详细解决方案

Springboot+Mybatis整合启动报Property sqlSessionFactory or sqlSessionTemplate are required

热度:31   发布时间:2023-12-16 23:43:21.0
  • 背景描述

在springboot整合mybatis的时候,启动的时候会报出如下的错误:(关键信息)

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

 下面还会报出:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available...Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available...Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available

网上搜索该问题大部分都是指向pom中对mybatis依赖的引用错误问题,或者是mapper扫描,数据源配置,下面推荐几个可以查看:

https://www.cnblogs.com/Lints/p/11298549.html

http://chengxudaren.com/blog/article/show/id/239.html

但是按照其正确配置操作后,仍然没有解决上述报错。

  • 问题解决

在pom中加入 druid 数据库连接池的依赖,如下:

<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.9</version>
</dependency>

重启项目,问题解决。

  • 原因分析

emmmm……尚待探索。感觉是这是一种投机的解决方式,待研究,待解疑。

  相关解决方案