背景
我参考MyBatis-Spring的文档搭建环境 https://mybatis.org/spring/zh/getting-started.html 完全按文档上操作,还是报以下错误。
报错信息Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-08 10:56:07.836 ERROR 16149 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [cn/wsdmteach/bi/conf/DatasourceConfig.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: No supported DataSource type found
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.22.jar:5.3.22]
解决办法
pom.xml增加以下依赖:
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2
重新启动项目,问题解决了。
总结我本来以为是文档有问题,最终我发现实际上问题是我看错了文档。 mybatis-spring还有一个Spring Boot的子项目,mybatis-spring的文档只是针对spring的。 正确文档看这里: http://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/
https://blog.csdn.net/a704397849/article/details/103275184