当前位置: 首页>后端>正文

springboot + tk.mybatis启动报错

简述:项目中使用了 tk.mybatis 的包 启动的时候报错
原因:tk.mybatis中的@MapperScan 依赖于org.mybatis包,这个包没引入。

报错内容:
java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class tk.mybatis.spring.annotation.MapperScan.factoryBean()

java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class tk.mybatis.spring.annotation.MapperScan.factoryBean()
    at java.lang.reflect.Method.getDefaultValue(Method.java:612) ~[na:1.8.0_351]
    at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:132) ~[na:1.8.0_351]
    at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85) ~[na:1.8.0_351]
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:266) ~[na:1.8.0_351]
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_351]
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_351]
    at java.lang.Class.createAnnotationData(Class.java:3521) ~[na:1.8.0_351]
    at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_351]
    at java.lang.Class.getDeclaredAnnotations(Class.java:3477) ~[na:1.8.0_351]
    at org.springframework.core.annotation.AnnotationsScanner.getDeclaredAnnotations(AnnotationsScanner.java:454) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.annotation.AnnotationsScanner.isKnownEmpty(AnnotationsScanner.java:492) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.annotation.TypeMappedAnnotations.from(TypeMappedAnnotations.java:251) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.annotation.MergedAnnotations.from(MergedAnnotations.java:351) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.annotation.MergedAnnotations.from(MergedAnnotations.java:330) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.type.StandardAnnotationMetadata.<init>(StandardAnnotationMetadata.java:86) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.type.StandardAnnotationMetadata.from(StandardAnnotationMetadata.java:175) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.core.type.AnnotationMetadata.introspect(AnnotationMetadata.java:127) ~[spring-core-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.<init>(AnnotatedGenericBeanDefinition.java:58) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.doRegisterBean(AnnotatedBeanDefinitionReader.java:253) ~[spring-context-5.3.9.jar:5.3.9]
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:147) ~[spring-context-5.3.9.jar:5.3.9]
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:137) ~[spring-context-5.3.9.jar:5.3.9]
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:168) ~[spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:143) ~[spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:136) ~[spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.SpringApplication.load(SpringApplication.java:699) [spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:426) [spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:337) [spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.3.jar:2.5.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.3.jar:2.5.3]
    at com.scienx.ScienxApplication.main(ScienxApplication.java:30) [classes/:na]

如图:


springboot + tk.mybatis启动报错,第1张

报错时的pom.xml 如图:(此时没有引入org.mybatis)


springboot + tk.mybatis启动报错,第2张

原因:tk.mybatis中的@MapperScan 依赖于org.mybatis包,这个包没引入。
如图:
点进去tk的MapperScan


springboot + tk.mybatis启动报错,第3张

点进去tk的MapperFactoryBean


springboot + tk.mybatis启动报错,第4张

注意:在tk的MapperFactoryBean中引入了org的包内容


springboot + tk.mybatis启动报错,第5张

解决方案:在pom.xml 中增加org.mybatis的包即可

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

解决效果:


springboot + tk.mybatis启动报错,第6张

springboot + tk.mybatis启动报错,第7张

启动成功


https://www.xamrdz.com/backend/3er1936025.html

相关文章: