1. 程式人生 > >at sun.reflect.generics.reflectiveObjects.ParameterizedTypeI

at sun.reflect.generics.reflectiveObjects.ParameterizedTypeI

匯入一個新專案,在自己電腦匯入失敗...

報錯,org.apache.ibatis.annotations.Param,如下:

在網上搜了之後說沒匯入ibatis的jar包,因為@Param這個類是ibatis的jar包中的,但是很奇怪,用的是mybatis,之前專案根本沒有匯入那個jar包,直覺告訴我這麼處理是不靠譜的,但是還是嘗試了一下,匯入jar包依賴後,錯誤馬上消失了,慶幸了一下。然而當tomcat執行起來的時候問題就出來了,顯示at sun.reflect.generics.reflectiveObjects.ParameterizedTypeI,這個錯誤原因真是看不懂,最後還是刪了之前導的jar包,直接修改mybatis版本為最新版本(可以在maven中央倉庫查),然後專案就正常了。


原因分析:

原因1:spring整合mybatis的時候,對mybatis的版本是有要求的,如下:

<dependency><--錯誤,不相容-->
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>

兩個mybatis版本不相容,把第一個dependency的mybatis版本提高的最新就可以解決這個問題了。改變後的結果如下所示:

<dependency><--提高mybatis版本後,正常相容-->
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.7</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>


原因2:兩臺電腦的eclipse版本不一致,自己電腦的版本較高,可能不同版本的相容性要求不一致,低版本的eclipse對這個相容性要求不高,所以沒有報錯,新版本的eclipse的對相容性有要求,所以報錯。