问题来源
在配置mybatisplus分页拦截器时,进行测试结果出现了这个问题,大致意思就是拦截器这个Bean无法创建成功,导致了后面一堆错误打印,找了很久还是没找到解决方法,气死了,后来。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mpInterceptor' defined in class path resource [com/cqut/config/MpConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor]: Factory method 'mpInterceptor' threw exception; nested exception is java.lang.NoClassDefFoundError: net/sf/jsqlparser/expression/Expression
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~
我的分页拦截器没错,为
解决方法
突然想到别人对问题来源的分析-可能是版本不对。于是我提高了mybatisplus的版本从3.4.1到了3.4.3,很好,解决了,没有错了。
总结
所以springboot2.7.7要搭配mybatisplus3.4.3或者其他的,不能搭配mybatisplus3.4.1,否则配置分页拦截器会出错。