SpringBoot+Mybatis-plus+tk.mybatis出现项目启动失败

遇到的问题

描述:在一个新建的模块内新增数据库连接+Mybatis-plus,添加依赖以后,出现启动失败。

报错信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mybatisInterceptorAutoConfiguration': Unsatisfied dependency expressed through field 'sqlSessionFactoryList'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\DELL\IdeaProjects\DBPT\dbpt-service\dbpt-auth\target\classes\mapper\CertificateAuthorizationMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [C:\Users\DELL\IdeaProjects\DBPT\dbpt-service\dbpt-auth\target\classes\mapper\CertificateAuthorizationMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'cn.org.enst.auth.domain.CertificateAuthorization'.  Cause: java.lang.ClassNotFoundException: Cannot find class: cn.org.enst.auth.domain.CertificateAuthorization

报错问题点截图如下:

原因

我这个问题是因为项目中两个依赖包发生冲突,很明显一个tk的mybatis和mybatis-plus发生了冲突,导致Springboot加载bean的时候出现问题。

解决方案

解决方案很简单,排除掉其中一个依赖即可。

通过pom文件排除以来写法如下:

<dependency>
            <groupId>cn.org.enst.cloud</groupId>
            <artifactId>dbpt-common-core</artifactId>
            <version>${dbpt.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>tk.mybatis</groupId>
                    <artifactId>mapper-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

注意:排除依赖的以来引入本项目中要写在pom文件上方,pom文件有加载顺序,尽量避免这个可能发生的问题。

修改前有tk.mybatis依赖在该项目中。

排除后该依赖会不加载即为成功。

排查思路

正常的排查思路应该是。

①controller层注解

②service层注解

③dao层注解或者启动类上的包扫描

④Autowired

⑤配置文件中mybatis相关配置

⑥pom文件依赖问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值