pagehelper / Mybatis-PageHelper

Mybatis通用分页插件
https://mybatis.io
MIT License
12.23k stars 3.13k forks source link

springboot 3 整合 pagehelper 报错 Caused by: java.lang.NoClassDefFoundError: net/sf/jsqlparser/statement/select/SelectBody #817

Open chentuan opened 6 months ago

chentuan commented 6 months ago

2024-05-15 11:44:39.626 ERROR [ main] [] o.s.boot.SpringApplication [820] : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': net/sf/jsqlparser/statement/select/SelectBody at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) at com.xstc.admin.AdminApplication.main(AdminApplication.java:18) Caused by: java.lang.NoClassDefFoundError: net/sf/jsqlparser/statement/select/SelectBody at com.github.pagehelper.PageHelper.setProperties(PageHelper.java:158) at com.github.pagehelper.PageInterceptor.setProperties(PageInterceptor.java:221) at com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration.afterPropertiesSet(PageHelperAutoConfiguration.java:65) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1797) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1747) ... 16 common frames omitted Caused by: java.lang.ClassNotFoundException: net.sf.jsqlparser.statement.select.SelectBody at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ... 21 common frames omitted

2024-05-15 11:44:42.650 WARN [ Thread-5] [] c.a.n.common.http.HttpClientBeanHolder [102] : [HttpClientBeanHolder] Start destroying common HttpClient 2024-05-15 11:44:42.650 WARN [ Thread-13] [] c.a.nacos.common.notify.NotifyCenter [136] : [NotifyCenter] Start destroying Publisher Disconnected from the target VM, address: '127.0.0.1:63053', transport: 'socket'

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.4.7</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.github.jsqlparser</groupId>
                <artifactId>jsqlparser</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.16</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.github.jsqlparser/jsqlparser -->
    <dependency>
        <groupId>com.github.jsqlparser</groupId>
        <artifactId>jsqlparser</artifactId>
        <version>4.9</version>
    </dependency>
abel533 commented 6 months ago

jsqlparser 4.9 的问题,jsqlparser 几乎每个版本都不兼容。

abel533 commented 6 months ago

4.9和4.7是兼容的,可以用下面方式进行配置:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>2.1.0</version>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser4.7</artifactId>
    <version>6.1.0</version>
</dependency>
<dependency>
    <groupId>com.github.jsqlparser</groupId>
    <artifactId>jsqlparser</artifactId>
    <version>4.9</version>
</dependency>
Wang-0122 commented 1 week ago

4.9和4.7是兼容的,可以用下面方式进行配置:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>2.1.0</version>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser4.7</artifactId>
    <version>6.1.0</version>
</dependency>
<dependency>
    <groupId>com.github.jsqlparser</groupId>
    <artifactId>jsqlparser</artifactId>
    <version>4.9</version>
</dependency>

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': net/sf/jsqlparser/statement/select/SelectBody at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1806) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) at com.stationdm.tsp.portal.TspPortalApplication.main(TspPortalApplication.java:20) Caused by: java.lang.NoClassDefFoundError: net/sf/jsqlparser/statement/select/SelectBody at com.github.pagehelper.PageHelper.setProperties(PageHelper.java:158) at com.github.pagehelper.PageInterceptor.setProperties(PageInterceptor.java:221) at com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration.afterPropertiesSet(PageHelperAutoConfiguration.java:65) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1802) ... 16 common frames omitted Caused by: java.lang.ClassNotFoundException: net.sf.jsqlparser.statement.select.SelectBody at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ... 21 common frames omitted

已添加上述依赖, 还是报错

image

Wang-0122 commented 1 week ago

` 亲测, 已解决 问题原因: jsqlparser版本问题

SpringBoot: 3.3.2 Mybatis-Plus: 3.5.5

思路如下:

com.github.yulichang mybatis-plus-join-boot-starter 1.4.6 -> com.github.yulichang mybatis-plus-join-boot-starter 1.5.2 其他依赖需要排除jsqlparser依赖

com.github.jsqlparser jsqlparser

com.github.jsqlparser jsqlparser ${jsqlparser.version}

4.4 -> 4.6 3.5.10 -> 3.5.16 3.5.3.1 -> 3.5.5 1.4.5 -> 2.1.0 com.baomidou mybatis-plus-boot-starter ${mybatis-plus.version} com.baomidou mybatis-plus-spring-boot3-starter ${mybatis-plus.version} `
Wang-0122 commented 1 week ago

image