1、解决springboot因为Error creating bean with name 'dataSource' defined in class path resource。。报错问题
2、错误代码详情:
Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Bean instantiation via factory method failed; nested exception is 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
译文创建类路径resource中定义的名为“dataSource”的bean时出错:通过工厂方法实例化bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql. sql]。:工厂方法' DataSource '抛出异常;嵌套异常是java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedDataBinder
3、在刚开始我搜索网上大部分答案是需要配置一个@SpringBootApplication(exclude={DruidDataSourceAutoConfigure.class, SecurityAutoConfiguration.class})注解,尝试了无数遍都没解决,还是报上面的错误,最后无奈摸索了两个多小时,发现是我的mybatis和druid坐标,是这两个坐标版本冲突造成的问题,当我刚开始使用的是mabatis版本3.4.3,druid版本为1.0.1,就会提示这样错误,通过查询得知,mybatis的3.4.3版本对应的druid版本为1.2.6,改过来后,运行正常,如图:
这两个版本可以不发生冲突