简体   繁体   中英

Spring Boot with MyBatis - @MapperScan error

I am trying to set up Spring Boot with MyBatis. When I try and launch my application, I am getting the following error:

java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()
    at java.lang.reflect.Method.getDefaultValue(Method.java:611)
    at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:128)
    at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85)     
    at ...
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
    at com.mydomain.Server.launch(Server.java:70)
    at com.mydomain.Server.main(Server.java:93)

I'm using the following versions in my pom.xml in order to get things set up:

  • spring-boot-dependencies @ 1.5.9.RELEASE
  • spring-cloud-dependencies @ Edgware.SR1
  • mybatis @ 3.4.5
  • mybatis-spring @ 1.3.1

I also have the following included:

  • mybatis-spring-boot-starter
  • spring-boot-configuration-processor
  • spring-cloud-config-client
  • spring-boot-starter-web
  • spring-boot-starter-actuator
  • spring-boot-starter

I'm not sure if there is a conflict or what, but it's not letting me set up my mappers. Any suggestions are happily welcomed.

You need to add this maven dependency:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
</dependency>

I had the same problem.
I tried mybatis-spring-boot : https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter/1.3.2
My application is running ok.

I hope it helps you.

OK - so the problem is a conflict between mybatis @ 3.4.5 and mybatis-spring @ 1.3.1 .

When I dropped mybatis @ 3.4.5 everything worked just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM