使用Mabatis-plus新增数据出错

使用Mabatis-plus新增数据出错


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class TestMapperTest extends TestCase {
    @Resource
    private TestMapper testMapper;

    @Test
    public void tsetInstant() {
        Test2 test2 = new Test2();
        test2.setContent("xxxxx");
           testMapper.insert(test2);
    }
}
Caused by: java.lang.ClassCastException: com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor cannot be cast to org.apache.ibatis.plugin.Interceptor
	at com.baomidou.mybatisplus.core.MybatisXMLConfigBuilder.pluginElement(MybatisXMLConfigBuilder.java:190)
	at com.baomidou.mybatisplus.core.MybatisXMLConfigBuilder.parseConfiguration(MybatisXMLConfigBuilder.java:112)
	... 69 more
	
	
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor cannot be cast to org.apache.ibatis.plugin.Interceptor


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小小 2022-07-11 13:43:49

同学你好

1、建议检查下相关jar是否导入成功。例如:

<!-- MyBatis-Plus依赖 -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus</artifactId>
    <version>3.3.2</version>
</dependency>

https://img1.sycdn.imooc.com//climg/62cbb63c09931a6c04610454.jpg

2、applicationContext.xml中是否更改配置SqlSessionFactory实现类

<bean id="sessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">

https://img1.sycdn.imooc.com//climg/62cbb705094b9fc609730252.jpg

祝学习愉快~

  • 提问者 qq_慕盖茨6087126 #1

    https://img1.sycdn.imooc.com//climg/62cd455d09dbf15630181860.jpg

    还是有这个问题,用源码pom.xml也有

    2022-07-12 17:57:17
  • 提问者 qq_慕盖茨6087126 #2

    https://img1.sycdn.imooc.com//climg/62cd455d09dbf15630181860.jpg

    2022-07-12 17:57:35
  • 同学你好,从截图来看,两次截图的报错信息可能是不一致的。出现该错误的原因可能是依赖版本冲突,建议将如下依赖修改为一致:

    https://img1.sycdn.imooc.com//climg/62cd4adc097ca13f04070854.jpg

    修改后或粘贴源码中pom.xml后,手动重新加载maven项目,再清除IDEA缓存重启测试运行试下。

    https://img1.sycdn.imooc.com//climg/62cd4b89095266ab06300322.jpg

    https://img1.sycdn.imooc.com//climg/62cd4b94099e1d4802790417.jpg

    祝学习愉快~

    2022-07-12 18:29:36
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师