Spring启动oracle驱动程序在运行时

时间:2017-07-28 18:00:00

标签: spring-boot spring-data-jpa ojdbc

我有一个Spring启动应用程序,我正在尝试添加oracle连接。我已经添加了一个@Entity类和Repository。

我已将oracle ojdbc8.jar添加到我当地的maven repo并将其放入gradle中

dependencies {
    ...
    compile group: 'com.oracle', name: 'ojdbc8', version:'12.2.0'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.3.RELEASE'
    ...
}

我的application.properties包含

spring.datasource.url="jdbc:oracle:thin:@//hostname.whatever:1521/blah"
spring.datasource.username="username"
spring.datasource.password="password"
spring.datasource.driver-class-name="oracle.jdbc.OracleDriver"

这一切都很好。但是当我部署(在tomcat下)时,我得到了

Caused by: 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.OracleDriver"

看起来很难找到驱动程序。还有什么我需要做的才能让它知道在哪里找到它吗?或者将其构建为存档的一部分?

我还构建了一个类似的测试应用程序,并将其指向本地mysql,以确保我没有疯狂,并且工作正常......不确定oracle有什么特别之处。

0 个答案:

没有答案