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……尚待探索。感覺是這是一種投機的解決方式,待研究,待解疑。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章