驱动程序:org.postgresql.Driver@3ed03652 为 URL 返回空值...在部署 Spring Boot 到 Heroku 时 [英] Driver:org.postgresql.Driver@3ed03652 returned null for URL... While deployin spring boot to Heroku
问题描述
我尝试在 Heroku 上部署我的应用程序,但有一些我无法修复的错误我的 application.poperties
I try deploy my application on Heroku, but have some errors which I can't fix my 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
我的应用程序类是用于启动应用程序的标准 Spring Boot 类
my Application class is standart spring boot class for application starting
我的 pom.xml(其中的一部分):
my pom.xml (part of it):
<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
如果有人解释我的错误,我将不胜感激
I would be grateful if somebody explain my mistake
推荐答案
您在 JDBC URL 中使用了 jdbc:postgres
而不是 jdbc:postgresql
(注意额外的ql
).
You are using jdbc:postgres
in your JDBC URL instead of jdbc:postgresql
(note the extra ql
).
Heroku 已经为您设置了 SPRING_DATASOURCE_URL
环境变量,因此您应该能够完全删除 application.properties
中的 spring.datasource
条目.
Heroku already sets SPRING_DATASOURCE_URL
environment variable for you, so you should be able to remove your spring.datasource
entries in application.properties
entirely.
如果您无法删除它们,请尝试:
If you are not able to remove them, try:
spring.datasource.url=${JDBC_DATABASE_URL}
如果这不起作用,那一定意味着您没有使用 Java buildpack 或其他东西.
If that doesn't work, it must mean you are not using the Java buildpack or something.
也一定要运行:
heroku pg:credentials --reset
这篇关于驱动程序:org.postgresql.Driver@3ed03652 为 URL 返回空值...在部署 Spring Boot 到 Heroku 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!