Spring Boot项目升级:Mybatis升级碰到的问题对应

在将SpringBoot从1.5.22升级到2.3.3并同时将Mybatis从1.3.5升级到2.1.3后,遇到了启动失败的问题,主要错误信息为Bean创建异常,原因在于XML映射文件中集合类型属性'children'定义不明确。解决方案是明确指定'children'的javaType为'list',从而成功解决了运行时问题。
摘要由CSDN通过智能技术生成

这篇文章记录一下Spring Boot从1.5.22升级至2.3.3后,升级Mybatis所碰到的问题。

目录


版本说明

  • Spring Boot版本:2.3.3

  • Mybatis升级前

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.5</version>
    </dependency>
    
  • Mybatis升级后

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>
    

问题现象

[main] ERROR org.springframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'SSOFilterConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SSOFilter': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SSOService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoSupport': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createSqlSessionFactoryBean' defined in class path resource [AAAA.class]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'URL [jar:file:/Users/liumiao/Desktop/BBB.jar!/BOOT-INF/lib/cd-2.1.7.jar!/CCC.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'URL [jar:file:/Users/liumiao/Desktop/BBB.jar!/BOOT-INF/lib/DDD.jar!/CCC.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Ambiguous collection type for property 'children'. You must specify 'javaType' or 'resultMap'.
...
org.apache.ibatis.builder.BuilderException: Ambiguous collection type for property 'children'. You must specify 'javaType' or 'resultMap'
...
WARN  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
...

修改示例


修改参考

参考了如下Mybatis官方内容,所提示的方法中没有解决本文的问题,但是给出了提示。

  • https://github.com/mybatis/mybatis-3/issues/364

修改方式

最终使用如下方式修改解决了升级时在运行阶段碰到的问题。

  • 修改前

    	<collection property="children" ofType="com.XXXX.YYYY" >
    		<result column="xxx_id" property="id" javaType="java.lang.Integer" jdbcType="INTEGER" />
    		<result column="yyy_name" property="name" javaType="java.lang.String" jdbcType="VARCHAR" />
    	</collection>
    
  • 修改后

    	<collection property="children" ofType="com.XXXX.YYYY"   javaType="list">
    		<result column="xxx_id" property="id" javaType="java.lang.Integer" jdbcType="INTEGER" />
    		<result column="yyy_name" property="name" javaType="java.lang.String" jdbcType="VARCHAR" />
    	</collection>
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值