简体   繁体   English

在spring tomcat应用程序中无法为连接URL'null创建类''的JDBC驱动程序

[英]Getting Cannot create JDBC driver of class '' for connect URL 'null in spring tomcat application

I am getting the following exception while getting datasource through jndi:通过 jndi 获取数据源时出现以下异常:

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException:
     Could not get JDBC Connection; nested exception is
     org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null

Tomcat's server.xml : Tomcat 的 server.xml :

     <Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
          username="test" password="test1234"
          url="*********"
          driverClass="oracle.jdbc.driver.OracleDriver"
          initialSize="5" maxWait="5000"
          maxActive="120" maxIdle="5"
          validationQuery="select 1"
          poolPreparedStatements="true"/>    

Tomcat's Context.xml : Tomcat 的 Context.xml :

<ResourceLink name="jdbc/testdb" global="jdbc/testdb"
type="javax.sql.DataSource" />     

Spring's servlet xml : Spring的servlet xml:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/testdb"  resource-ref="true" />

and final Web.xml :最后的 Web.xml :

   <resource-ref>
       <description>Resource reference to database</description>
       <res-ref-name>jdbc/testdb</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

Could somebody please help me?有人可以帮我吗?

Error Stack trace :错误堆栈跟踪:

  Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

尝试driverClassName而不是driverClass

driverClassName="oracle.jdbc.driver.OracleDriver"

I am using Eclipse STS 3.9.3, tomcat 8.5 and Spring Boot 2.0.0.RELEASE我正在使用 Eclipse STS 3.9.3、tomcat 8.5 和 Spring Boot 2.0.0.RELEASE

I spent my entire morning about this problem.我整个上午都在解决这个问题。 So, I did a lot of things to solve:所以,我做了很多事情来解决:

  1. Remove jdbc dependence from my pom.从我的 pom.xml 中删除 jdbc 依赖。

     <!-- dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency-->
  2. Declaration resource TOMCAT_HOME/CONF/server.xml whit factory:声明资源 TOMCAT_HOME/CONF/server.xml whit factory:

     <GlobalNamingResources> ... <Resource name="jdbc/postgres_jndi" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://xxx.xxx.xx.xxx:5432/db" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true" timeBetweenEvictionRunsMillis="10000" removeAbandonedTimeout="60" logAbandoned="true" username="xxx" password="xxxxxx" maxTotal="20" maxIdle="10" maxWaitMillis="-1"/> ... </GlobalNamingResources>

    I realized that I was using Eclipse STS.我意识到我正在使用 Eclipse STS。 The tomcat resource on server.xml only works after I put the resource declaration in server.xml inside of "Tomcat v8.5 Server at localhost-config" folder in my Server project. server.xml 上的 tomcat 资源仅在我将资源声明放入我的服务器项目的“Tomcat v8.5 Server at localhost-config”文件夹中的 server.xml 后才有效。 Did not work on TOMCAT_HOME/conf folder in server.xml file.不适用于 server.xml 文件中的 TOMCAT_HOME/conf 文件夹。

  3. Change my application.yml to:将我的 application.yml 更改为:

     spring: datasource: platform: postgres jndi-name: java:comp/env/jdbc/postgres_jndi type: javax.sql.DataSource driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: validate database-platform: org.hibernate.dialect.PostgreSQL9Dialect database: POSTGRESQL show-sql: true #Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented. properties: hibernate: temp: use_jdbc_metadata_defaults: false

I think that you miss java:comp/env/ yours will be like this:我认为你想念java:comp/env/你的会是这样的:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/testdb" resource-ref="true" />

A application.properties will be like: application.properties 将类似于:

    spring.datasource.platform= postgres
    spring.datasource.jndi-name= java:comp/env/jdbc/postgres_jndi
    spring.datasource.type= javax.sql.DataSource
    spring.datasource.driver-class-name= org.postgresql.Driver
    spring.jpa.hibernate.ddl-auto= validate
    spring.jpa.hibernatedatabase-platform= org.hibernate.dialect.PostgreSQL9Dialect
    spring.jpa.database= POSTGRESQL
    spring.jpa.show-sql= true
    spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
  1. Define a context.xml file in src/main/webapp/META-INF/context.xml with definition:在 src/main/webapp/META-INF/context.xml 中定义一个 context.xml 文件,定义如下:

     <?xml version="1.0" encoding="UTF-8"?> <Context path="/myapp"> <ResourceLink global="jdbc/postgres_jndi" name="jdbc/postgres_jni" type="javax.sql.DataSource"/> </Context>
  2. Put the file postgresql-42.2.2.jar in the TOMCAT_HOME/lib将文件 postgresql-42.2.2.jar 放入 TOMCAT_HOME/lib

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有mysql的Tomcat:“无法为连接URL&#39;null&#39;创建类”的JDBC驱动程序” - Tomcat with mysql : “ Cannot create JDBC driver of class '' for connect URL 'null' ” 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat + MySQL + Spring MVC - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat + MySQL + Spring MVC Java Spring Tomcat8:无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序 - Java Spring Tomcat8: Cannot create JDBC driver of class '' for connect URL 'null' Tomcat 8 + MySQL + Spring + JPA-无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序 - Tomcat 8 + MySQL + Spring + JPA - Cannot create JDBC driver of class '' for connect URL 'null' 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat和SQL Server JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat & SQL Server JDBC driver 在tomcat 6中创建和使用数据源时,无法为连接URL&#39;null&#39;-:ERROR创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' -:ERROR while creating and using a Datasource in tomcat 6 Tomcat,Java和SQL Server 2008 R2:无法为连接URL&#39;&#39;创建类&#39;&#39;的JDBC驱动程序 - Tomcat, Java & SQL Server 2008 R2: Cannot create JDBC driver of class '' for connect URL 'null' Tomcat 9 / JNDI 数据源 - 无法为连接 URL &#39;null&#39; 创建类 &#39;&#39; 的 JDBC 驱动程序 - Tomcat 9 / JNDI DataSource - Cannot create JDBC driver of class '' for connect URL 'null' 无法一直为连接URL&#39;null创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null all the time 无法为连接URL&#39;null&#39;Oracle创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' Oracle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM