![](/img/trans.png)
[英]Spring Boot - PostgreSQL driver cannot be located in classpath
[英]Driver:org.postgresql.Driver@3ed03652 returned null for URL… While deployin spring boot to Heroku
我嘗試在 Heroku 上部署我的應用程序,但有一些我無法修復我的 application.poperties 的錯誤
spring.mvc.view.prefix = /WEB-INF/view/
spring.mvc.view.suffix = .jsp
spring.datasource.url = jdbc:postgres://user:pass@ec2-54-247-166-129.eu-west-1.compute.amazonaws.com:5432/database
# Username and password
spring.datasource.username = user
spring.datasource.password = pass
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.datasource.driverClassName=org.postgresql.Driver
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
我的 Application 類是用於應用程序啟動的標准 Spring Boot 類
我的 pom.xml(它的一部分):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
<build>
<finalName>spring</finalName>
<plugins>
<!-- Spring Boot Maven -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>8.0.30.2</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我收到的錯誤
> 12:06:42.061 INFO 12352 --- [ost-startStop-1]
> o.s.b.w.servlet.FilterRegistrationBean : Mapping filter:
> 'applicationContextIdFilter' to: [/*] 2017-03-10 12:06:42.488 ERROR
> 12352 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool :
> Unable to create initial connections of pool.
>
> java.sql.SQLException: Driver:org.postgresql.Driver@760cf594 returned
> null for
> URL:jdbc:postgres://fqwebtafwgsgmp:17ff02102b2660162ce1b053ef28340dfa7cf4d71e14b4bf1b187a8ad7d36579@ec2-54-247-166-129.eu-west-1.compute.amazonaws.com:5432/daapseha11ekml
> at
> org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:329)
> ~[tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
> ~[tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732)
> [tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:664)
> [tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479)
> [tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
> [tomcat-jdbc-8.5.11.jar:na] at
> org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
> [tomcat-jdbc-8.5.11.jar:na] at
如果有人解釋我的錯誤,我將不勝感激
您在 JDBC URL 中使用jdbc:postgres
而不是jdbc:postgresql
(注意額外的ql
)。
Heroku上已經設置SPRING_DATASOURCE_URL
環境變量為你,所以你應該能夠刪除您spring.datasource
中的條目application.properties
完全。
如果您無法刪除它們,請嘗試:
spring.datasource.url=${JDBC_DATABASE_URL}
如果這不起作用,那一定意味着您沒有使用 Java buildpack 或其他東西。
還要確保運行:
heroku pg:credentials --reset
您的問題可能是您的連接網址。 您在 url 中有有效的用戶名和密碼。
將您的spring.datasource
設置更改為:
spring.datasource.url = jdbc:postgres://ec2-54-247-166-129.eu-west-1.compute.amazonaws.com:5432/database
# Username and password
spring.datasource.username = user
spring.datasource.password = pass
附注。 我嘗試並連接到您的數據庫實例,因此我會盡快更改它們。
使用 Spring Boot:2.3.4 和驅動程序版本:42.2.18
特性
spring:
datasource:
password: ${RDBMS_PASSWORD:pass}
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://${DATABASE_HOST:ec2-54-217-213-79.eu-west-1.compute.amazonaws.com}:${DATABASE_PORT:5432}/${DATABASE_NAME:dbName}?sslmode=require
username: ${DATABASE_USER:user}
initialization-mode: always
initialize: true
schema: classpath:/schema.sql
data: classpath:/data.sql
jpa:
hibernate:
ddl-auto: none
show-sql: true
generate-ddl: false
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
注意網址:jdbc:postgresql://
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.