错误信息
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.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.IllegalStateException: Unable to create XADataSource instance from ‘com.mysql.jdbc.jdbc2.optional.MysqlXADataSource’
分析原因
分析代码得知:
当 getXa().getDataSourceClassName() 为空时,XADataSource 将从url(连接串)中分析出DataSourceClassName,com.mysql.jdbc.jdbc2.optional.MysqlXADataSource,而这个 又不存在,而报错!

解决方法
在配置中显示指定:
com.mysql.cj.jdbc.MysqlXADataSource
com.alibaba.druid.pool.xa.DruidXADataSource
xa:
dataSourceClassName: com.mysql.cj.jdbc.MysqlXADataSource

本文分析了Spring Boot项目中出现的关于XADataSource配置错误的原因,并提供了具体的解决方案,包括如何正确配置MysqlXADataSource。

1600

被折叠的 条评论
为什么被折叠?



