作者:黑鸽子 | 来源:互联网 | 2023-09-16 09:33
背景描述在springboot整合mybatis的时候,启动的时候会报出如下的错误:(关键信息)Invocationofinitmethodfailed;nestedexcept
在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 数据库连接池的依赖,如下:
com.alibaba
druid-spring-boot-starter
1.1.9
重启项目,问题解决。
emmmm……尚待探索。感觉是这是一种投机的解决方式,待研究,待解疑。