当前位置:   article > 正文

Spring Boot项目升级:Mybatis升级碰到的问题对应_org/mybatis/spring/boot/autoconfigure/mybatisdepen

org/mybatis/spring/boot/autoconfigure/mybatisdependsondatabaseinitialization

这篇文章记录一下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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • Mybatis升级后

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

问题现象

[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
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

修改示例


修改参考

参考了如下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>
    
    • 1
    • 2
    • 3
    • 4
  • 修改后

    	<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
    • 2
    • 3
    • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/498187
推荐阅读
相关标签
  

闽ICP备14008679号