spring boot 因mybatis版本引发的问题

使用spring boot整合项目的时候,遇到了一个异常,如下:

2018-06-03 20:44:17.660  WARN 301924 --- 
[           main] o.s.b.f.s.DefaultListableBeanFactory     :
Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'roleDao' defined in file
[B:\workspace_spring\resume\baseservice\target\classes\com\ma\base\dao\RoleDao.class]: 
Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; 
nested exception is 
Error creating bean with name 'sqlSessionFactory' defined in 
class path resource
[org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: 
 org.springframework.beans.BeanInstantiationException: 
Factory method 'sqlSessionFactory' threw exception;
 nested exception is java.lang.NoSuchMethodError: 
 org.mybatis.spring.SqlSessionFactoryBean.setVfs(Ljava/lang/Class;)V

根据异常信息,MybatisAutoConfiguration类中出现了方法调用异常,打开源码查看

  @Bean
  @ConditionalOnMissingBean
  public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setVfs(SpringBootVFS.class);

发现 factory.setVfs(SpringBootVFS.class)在SqlSessionFactoryBean类中不存在,导致sqlsesessionFactory创建失败。纠结了很久,找了很多资料,查看spring boot版本,又看了mybatis-spring-boot-starter整合包的版本,都没有问题的,为什么我的项目启动就遇到了这种问题呢!!!无奈之下,对比了之前的项目和现在项目结构的maven引入jar包结构,我坑。。。结果居然是在父工程中定义了这个依赖

<dependency>
    <groupId>org.mybatisgroupId>
    <artifactId>mybatis-springartifactId>
    <version>1.2.2version>
dependency>

坑爹…原来就是在父工程中这里搞得鬼,去掉后,在此查看maven引入的版本mybatis-spring-1.3.1,OK。万事大吉,启动正常。

你可能感兴趣的:(项目总结)