赞
踩
这篇文章记录一下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官方内容,所提示的方法中没有解决本文的问题,但是给出了提示。
最终使用如下方式修改解决了升级时在运行阶段碰到的问题。
修改前
<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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。