2 dwc136251 dwc136251 于 2017.12.25 16:48 提问

springboot整合jpa时报错

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-25 16:35:58.957 ERROR 8816 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

Caused by: java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

9个回答

dcxy0
dcxy0   Ds   Rxr 2017.12.25 23:20
已采纳

java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

你这oracle驱动没加载啊,

http://mvnrepository.com/artifact/oracle

要对应你的oracle版本,上面是maven仓库的信息(ojdbc)

dwc136251
dwc136251   2017.12.25 16:48

下面是pom配置文件:<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.example.thymeleaf
thymeleaf
0.0.1-SNAPSHOT
jar
thymeleaf
Demo project for Spring Boot And Thymeleaf

org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
<!-- lookup parent from repository -->


UTF-8
UTF-8
1.8


<!-- Spring Boot Web 依赖 -->

org.springframework.boot
spring-boot-starter-thymeleaf

<!-- Spring Boot Mybatis 依赖 -->

org.mybatis.spring.boot
mybatis-spring-boot-starter
1.0.0

<!-- oracle -->

com.oracle
ojdbc6
${ojdbc6.version}

<!-- 支持 @ConfigurationProperties 注解 -->

org.springframework.boot
spring-boot-configuration-processor
true


junit
junit
test

<!-- tomcat 的支持. -->

org.springframework.boot
spring-boot-starter-tomcat
provided


org.apache.tomcat.embed
tomcat-embed-jasper
provided


org.springframework.boot
spring-boot-starter-test
test


org.springframework.boot
spring-boot-starter-data-jpa


com.oracle
ojdbc14
10.2.0.4.0
runtime





org.springframework.boot
spring-boot-maven-plugin



dwc136251
dwc136251   2017.12.25 16:49

下面是application.properties:

访问端口

server.port=8080

指定日志文件位置

logging.file=E:/spring-boot-thymeleaf.log

指定日志输出级别

logging.level.org.springframework.web=ERROR
logging.level.org.apache=ERROR
logging.level.org.springframework.boot.web=ERROR
#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end
#oracle配置
spring.jpa.database=oracle
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:DWC
spring.datasource.username=test
spring.datasource.password=test
#1
spring.jpa.hibernate.ddl-auto=update
#2
spring.jpa.show-sql=true
spring.jackson.serialization.indent-output=true

kun_tostudy
kun_tostudy   Rxr 2017.12.25 16:56

Cannot load driver class: oracle.jdbc.driver.OracleDriver
不能加载驱动 !!!

qq_38334913
qq_38334913   2017.12.25 17:07

看着像 oracle ojdbc的版本不对,ojdbc6 配的是jdk6,换个版本试试,中央仓库应该没有资源,你要重新下载个,然后打到本地的maven仓库

qq_38334913
qq_38334913 回复朱明明啊: 你的太长了,没看到你的是、就是14...
大约 2 个月之前 回复
qq_38334913
qq_38334913 ojdbc14
大约 2 个月之前 回复
Small_Mouse0
Small_Mouse0   Rxr 2017.12.25 17:17
 Cannot load driver class: oracle.jdbc.driver.OracleDriver

报错信息确实说的是不能加载驱动,,题主检查下配置依赖了没,,

wilsonzq
wilsonzq   2017.12.25 18:28

是不是没有引入mybatis包,


org.mybatis
mybatis
3.4.5

wilsonzq
wilsonzq   2017.12.25 18:30
jared_he2017
jared_he2017   2017.12.25 18:45

我也碰到过,这个是因为你的配置文件中配置jpa的那几个属性后面有空格,在springboot的jpa配置中,jpa的那几个属性=后面是不能有空格的。。。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!