spring boot集成mybatis报错 java.lang.IllegalStateException: No supported DataSource type found

背景

我参考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增加以下依赖:

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.2.2</version>
</dependency>

重新启动项目,问题解决了。

总结

我本来以为是文档有问题,最终我发现实际上问题是我看错了文档。
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
mybatis-puls报错java.lang.illegalstateexception: no typehandler found fo的原因是没有找到合适的类型处理器。 MyBatis-Puls是MyBatis的一个插件,用于增强MyBatis框架的功能。在使用MyBatis-Puls的过程中,如果出现了"no typehandler found fo"的错误,通常是由于没有正确配置类型处理器所致。 类型处理器(TypeHandler)是MyBatis中用于将数据库中的数据类型与Java中的数据类型进行转换的一个重要组件。当MyBatis-Puls在映射对象和数据库表之间进行数据转换时,会根据声明的类型处理器来进行相应的转换操作。 要解决这个错误,我们需要确保在MyBatis-Puls的配置文件中正确配置了类型处理器。 首先,确认错误信息中提到的类型处理器确实存在于项目中。如果没有找到合适的类型处理器,我们可以自定义一个类型处理器,实现TypeHandler接口,并在配置文件中进行注册。 其次,确认类型处理器的配置是否正确。在MyBatis-Puls的配置文件中,可以通过typeHandlers标签来配置类型处理器。确保需要的类型处理器已经被正确配置。 最后,检查映射对象的属性与数据库字段的类型是否匹配。如果属性的类型与数据库字段的类型不一致,也会导致类型处理器报错。确保属性和字段的类型匹配,或者在MyBatis-Puls的配置文件中配置适当的类型处理器来解决类型转换问题。 总之,当出现mybatis-puls报错java.lang.illegalstateexception: no typehandler found fo时,需要检查是否正确配置了类型处理器,确保类型处理器存在、配置正确,并且映射对象属性与数据库字段类型匹配,以解决该错误。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值