spring boot 2.x版本:java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedDataBinder

标题 ##搭建spring boot 2.0.3版本

使用alibaba的druid数据库连接池,com.github.pagehelper的分页插件,启动项目报错。
部分错误日志如下:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedDataBinder
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 72 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedDataBinder
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder.bind(DruidDataSourceBuilder.java:48) ~[druid-spring-boot-starter-1.1.0.jar:na]
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder.build(DruidDataSourceBuilder.java:41) ~[druid-spring-boot-starter-1.1.0.jar:na]
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.dataSource(DruidDataSourceAutoConfigure.java:44) ~[druid-spring-boot-starter-1.1.0.jar:na]
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure$$EnhancerBySpringCGLIB$$9f99be1d.CGLIB$dataSource$0() ~[druid-spring-boot-starter-1.1.0.jar:na]
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure$$EnhancerBySpringCGLIB$$9f99be1d$$FastClassBySpringCGLIB$$dd45feef.invoke() ~[druid-spring-boot-starter-1.1.0.jar:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure$$EnhancerBySpringCGLIB$$9f99be1d.dataSource() ~[druid-spring-boot-starter-1.1.0.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_111]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 73 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedDataBinder
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_111]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_111]
    ... 86 common frames omitted

错误提示:java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedDataBinder
boot.bind下找不到RelaxedDataBinder这个方法
查看API发现,这个org.springframework.boot.bind 包已经删掉了,导致RelaxedPropertyResolver这个方法已经不可用了.

解决方案一:使用jdbc连接

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>

附application.yml配置:

server:
  port: 8080

spring:
    datasource:
        name: test
        url: jdbc:mysql://127.0.0.1:3306/mytest
        username: root
        password: 123456
        driver-class-name: com.mysql.jdbc.Driver
mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  type-aliases-package: com.example.spring_boot.bean

解决方案二:boot版本改为1.5.x版本

附alibaba的druid数据库连接池

        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druid-spring-boot-starterartifactId>
            <version>1.1.0version>
        dependency>

com.github.pagehelper分页插件

        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelper-spring-boot-starterartifactId>
            <version>1.1.2version>
        dependency>

附application.yml配置:

server:
  port: 8080

spring:
    datasource:
        name: test
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
          driver-class-name: com.mysql.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/mytest
          username: root
          password: 123456
mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  type-aliases-package: com.example.spring_boot.bean

#pagehelper
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check

你可能感兴趣的:(ErrorList,Spring,Boot)