Java 驱动程序:org.postgresql。Driver@3ed03652为URL返回null。。。在将spring boot部署到Heroku时
我尝试在Heroku上部署我的应用程序,但有一些错误无法修复 我的应用程序.popertiesJava 驱动程序:org.postgresql。Driver@3ed03652为URL返回null。。。在将spring boot部署到Heroku时,java,spring,postgresql,maven,heroku,Java,Spring,Postgresql,Maven,Heroku,我尝试在Heroku上部署我的应用程序,但有一些错误无法修复 我的应用程序.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
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
我的应用程序类是standart spring启动类,用于应用程序启动
my pom.xml(它的一部分):
org.springframework.boot
springbootstarter缓存
org.postgresql
postgresql
春天
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven依赖插件
包裹
复制
com.github.jsimone
webapprunner
8.0.30.2
webapp-runner.jar
我收到的错误
> 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
>12:06:42.061信息12352---[ost-startStop-1]
>o.s.b.w.servlet.FilterRegistrationBean:映射筛选器:
>“applicationContextIdFilter”收件人:[/*]2017-03-10 12:06:42.488错误
>12352---[main]o.a.tomcat.jdbc.pool.ConnectionPool:
>无法创建池的初始连接。
>
>java.sql.SQLException:Driver:org.postgresql。Driver@760cf594返回
>无效
>URL:jdbc:postgres://fqwebtafwgsgmp:17ff02102b2660162ce1b053ef28340dfa7cf4d71e14b4bf1b187a8ad7d36579@ec2-54-247-166-129.eu-west-1.compute.amazonaws.com:5432/daapseha11ekml
>在
>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.(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
如果有人能解释我的错误,我将不胜感激您的问题可能是您的连接url。您在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
另外,我尝试并连接到您的db实例,以便尽快更改它们。您在jdbc URL中使用的是
jdbc:postgres
,而不是jdbc:postgresql
(请注意额外的ql
)
Heroku已经为您设置了SPRING\u DATASOURCE\u URL
环境变量,因此您应该能够完全删除application.properties中的SPRING.DATASOURCE
条目
如果无法删除它们,请尝试:
spring.datasource.url=${JDBC_DATABASE_URL}
如果这不起作用,那一定意味着您没有使用Java buildpack或其他东西
另外,请确保运行:
heroku pg:credentials --reset
使用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
请注意url:jdbc:postgresql://
Runheroku pg:credentials--reset
asap URL中的用户名和密码是可以接受的。问题是postgres
而不是postgresql
非常感谢。我真的很想念字符串末尾的ql)我花了几乎一天的时间解决这个问题并上网搜索答案。非常感谢。还有一个注意事项,您应该在url中包含sslmode=require,以便使用heroku
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