您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
在对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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。