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

  • 背景描述

在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……尚待探索。感觉是这是一种投机的解决方式,待研究,待解疑。

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值