问题场景
今天小编在MyBatis
整合Spring
的时候,使用到了@MapperScan
,在启动期出现了一个错误:
Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()
对于这个错误,小编也是倍感无奈,怎么会出现这个错误呢,看一下我的依赖有没有错误:
compile(project(":spring-context"))
// compile(project(":spring-instrument"))
// https://mvnrepository.com/artifact/cglib/cglib
compile group: 'cglib', name: 'cglib', version: '2.2.2'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
// https://mvnrepository.com/artifact/org.mybatis/mybatis
compile group: 'org.mybatis', name: 'mybatis', version: '3.5.2'
// https://mvnrepository.com/artifact/org.mybatis/mybatis-spring
compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.2'
完全没得毛病呀,他妈的,究竟是哪里出现了问题呢,小编这时将SpringFramework 源码从github 上clone 下来了,导入idea 开始寻找问题所在。。。
问题根源
经过不懈的努力,小编终于找到了问题根源,在AnnotationsScanner
类中的这个方法:
static Annotation[] getDeclaredAnnotations(AnnotatedElement source, boolean defensive) {
boolean cached = false;
Annotation[] annotations = declaredAnnotationCache.get(source);
if (annotations != null) {
cached =