Spring Boot建立DataSource時遇到的錯誤:No supported DataSource type found
在對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 omitted Caused 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裡指定以下三個中的任意一個:
1. COMMONS-DBCP
2. TOMCAT-JDBC
3. 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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10314474/viewspace-2200344/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Spring Boot + Mybatis + Spring MVC環境配置(三):DataSource配置Spring BootMyBatisMVC
- Spring boot ElasticSearch,出現ElasticsearchRepository.refresh()! No property refresh found for type錯誤...Spring BootElasticsearch
- spring datasource 配置及事務管理Spring
- Idea啟動專案報{dataSource-1} closed錯誤Idea
- 苞米豆的多資料來源 → dynamic-datasource-spring-boot-starter,挺香的!Springboot
- Spring DataSource>DBCP & C3P0Spring
- Spring Boot配置是遇到錯誤:jdbcUrl is required with driverClassNameSpring BootJDBCUI
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource couldAI
- 使用DataSource-Proxy在Spring Boot中記錄SQL語句 - Vlad MihalceaSpring BootSQL
- No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1BeanJavaSQLAIAST
- 連線oracle資料庫時,報錯:{dataSource-1} init errorOracle資料庫Error
- 出現錯誤 Project ‘org.springframework.boot:spring-boot-starter-parent’ not foundProjectSpringFrameworkboot
- Spring的DataSource配置、將Hibernate配置全部寫到Spring配置Spring
- 關於mybatis tomcat 和jetty啟動報 {dataSource-1} inited 錯誤的記錄MyBatisTomcatJetty
- GridView和DataSource的聯合使用View
- 有人熟悉jboss的datasource設定嗎?
- Springboot 啟動時不報錯一直卡住,{dataSource-1} initedSpring Boot
- 建立cache group 時遇到 錯誤5120 時候的解決方案
- Spring Boot 2.5.0 釋出:支援Java16、Gradle 7、Datasource初始化機制調整Spring BootJavaGradle
- 啟動tomcat時,日誌裡大量輸出建立資料來源dataSource的日誌Tomcat
- 部署 SAP UI5 應用到 SAP BTP 時遇到的 fiori not found 錯誤訊息UI
- Error creating bean with name ‘dataSource‘ErrorBean
- 如何將InputStream轉換為DataSource
- 在jboss中如何取得sqlserver的datasource.??SQLServer
- 請教。在ejb中用DataSource連線資料庫,報錯!資料庫
- CMP DataSource問題,尋求解決方案
- 使用React Hooks時遇到的錯誤提示ReactHook
- 使用flashback database 特性時遇到的錯誤Database
- Grafana的Datasource外掛開發實踐二Grafana
- Grafana的Datasource外掛開發實踐一Grafana
- 寫一個Spark DataSource的隨手筆記Spark筆記
- 請教高手 關於STRUTS DATASOURCE的問題
- Maven建立專案遇到導包錯誤:Maven
- spring boot 全域性錯誤處理Spring Boot
- 標準LO Datasource增強知識點
- Spring boot/Spring 統一錯誤處理方案的使用Spring Boot
- 七、Spring Boot 錯誤處理原理 & 定製錯誤頁面Spring Boot
- Spring Boot返回靜態錯誤頁面Spring Boot