iis服务器助手广告
返回顶部
首页 > 资讯 > 精选 >Spring Boot创建DataSource时遇到的错误:No supported DataSource type found
  • 409
分享到

Spring Boot创建DataSource时遇到的错误:No supported DataSource type found

2023-06-02 22:06:48 409人浏览 泡泡鱼
摘要

在对Spring Boot进行DataSource配置的时候遇到一个错误Caused by: org.springframework.beans.BeanInstantiationException: Fail

在对Spring Boot进行DataSource配置的时候遇到一个错误

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'testDataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]    ... 93 common frames omittedCaused by: java.lang.IllegalStateException: No supported DataSource type found    at org.springframework.boot.jdbc.DataSourceBuilder.getType(DataSourceBuilder.java:146) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]    at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:74) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]    at com.kai.demo.DataSourceConfig.testDataSource(DataSourceConfig.java:37) ~[classes/:na]    at com.kai.demo.DataSourceConfig$$EnhancerBySprinGCGLIB$$e66334f9.CGLIB$testDataSource$3(<generated>) ~[classes/:na]    at com.kai.demo.DataSourceConfig$$EnhancerBySpringCGLIB$$e66334f9$$FastClassBySpringCGLIB$$99581351.invoke(<generated>) ~[classes/:na]    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]    at com.kai.demo.DataSourceConfig$$EnhancerBySpringCGLIB$$e66334f9.testDataSource(<generated>) ~[classes/:na]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_121]    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]    ... 94 common frames omitted

原因是在使用DataSourceBuilder时需要在classpath里指定以下三个中的任意一个:

      COMMONS-DBCP

      Tomcat-JDBC

      HIKARICP


于是在pom.xml添加了HiKariCP的依赖

<dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>3.2.0</version></dependency>

错误就没有了

参考地址:https://stackoverflow.com/questions/44635962/error-when-create-datasource

--结束END--

本文标题: Spring Boot创建DataSource时遇到的错误:No supported DataSource type found

本文链接: https://www.lsjlt.com/news/231530.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作