ShardingSphere和MybatisPlus版本問題

Github:https://github.com/HealerJean

博客:http://blog.healerjean.com

錯誤來源

我使用的ShardingSphere和MybatisPlus做的分庫分表,當版本分表爲如下的時候沒有任何問題

<!--mybatis-plus-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.3.1.tmp</version>
</dependency>

<!--sharding jdbc 開始-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.0.0-RC1</version>
</dependency>

但是在我要測試XA事務的時候,要用到ShardingSphere版本爲4.0.0-RC2,這個時候啓動不論怎麼樣都是報錯,錯誤信息如下

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.refresh[557]

解決錯誤

博主上網一頓百度,用盡了全身力氣,從下午幹到了晚上9點。終於在Github上找到了問題,同時給我很好了找到了一個學習和找錯的經驗。一有問題先Google,如果關鍵詞很明顯再Google上搜不到。那怎麼辦?

找源頭唄,找ShardingSphereMybatisPlus的開源項目,肯定有人去提交bug,或者去問問題。那裏纔是程序員的天堂。

果然:我看到了 https://github.com/apache/incubator-shardingsphere/issues/2712

原因就在於我使用的Springboot版本的alibaba.druid

大神給出了兩種解決思路,第一種當然是屁話

1.ShardingSphere 4.0.0-RC1 搭配 MyBatis、druid-spring-boot-starter使用。

2.ShardingSphere 4.0.0-RC2 或者RC3 搭配 MyBatis、com.alibaba.druid(非springboot版本)使用。

3.希望引起ShardingSphere注意,修復bug

<!-- 數據源 -->
<!--<dependency>-->
<!--<groupId>com.alibaba</groupId>-->
<!--<artifactId>druid-spring-boot-starter</artifactId>-->
<!--</dependency>-->  

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.21</version>
</dependency>



<!--mybatis-plus-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>


<!--sharding jdbc 開始-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.0.0-RC2</version>
</dependency>       
        

ContactAuthor

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章