简体   繁体   English

驱动程序:org.postgresql.Driver@3ed03652 为 URL 返回空值...在部署 Spring Boot 到 Heroku 时

[英]Driver:org.postgresql.Driver@3ed03652 returned null for URL… While deployin spring boot to Heroku

I try deploy my application on Heroku, but have some errors which I can't fix my application.poperties我尝试在 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

my Application class is standart spring boot class for application starting我的 Application 类是用于应用程序启动的标准 Spring Boot 类

my pom.xml (part of it):我的 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>

Error which I receive我收到的错误

> 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如果有人解释我的错误,我将不胜感激

You are using jdbc:postgres in your JDBC URL instead of jdbc:postgresql (note the extra ql ).您在 JDBC URL 中使用jdbc:postgres而不是jdbc:postgresql (注意额外的ql )。

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. Heroku上已经设置SPRING_DATASOURCE_URL环境变量为你,所以你应该能够删除您spring.datasource中的条目application.properties完全。

If you are not able to remove them, try:如果您无法删除它们,请尝试:

spring.datasource.url=${JDBC_DATABASE_URL}

If that doesn't work, it must mean you are not using the Java buildpack or something.如果这不起作用,那一定意味着您没有使用 Java buildpack 或其他东西。

Also be sure to run:还要确保运行:

heroku pg:credentials --reset

Your problem is probably your connection url.您的问题可能是您的连接网址。 You have the valid username and password in the url.您在 url 中有有效的用户名和密码。

Change your spring.datasource settings to:将您的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

PS.附注。 I tried and connected to your db instance so I would change them ASAP.我尝试并连接到您的数据库实例,因此我会尽快更改它们。

Using Spring Boot: 2.3.4 and driver version: 42.2.18使用 Spring Boot:2.3.4 和驱动程序版本:42.2.18

properties特性

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

attention to the url: jdbc:postgresql://注意网址:jdbc:postgresql://

在此处输入图片说明

暂无
暂无

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

相关问题 Spring 引导 - PostgreSQL 驱动程序无法位于类路径中 - Spring Boot - PostgreSQL driver cannot be located in classpath 获取SQLException:当使用系统属性定义资源时,Driver:org.hsqldb.jdbcDriver为tomee中的URL返回null - Getting SQLException: Driver:org.hsqldb.jdbcDriver returned null for URL in tomee when Resource is defined with system properties 获取SQLException:Driver:org.hsqldb.jdbcDriver为tomee中的URL返回null - Getting SQLException: Driver:org.hsqldb.jdbcDriver returned null for URL in tomee 找不到icCube驱动程序:org.postgresql.Driver - icCube driver not found: org.postgresql.Driver java.lang.ClassNotFoundException:春季的org.postgresql.Driver - java.lang.ClassNotFoundException: org.postgresql.Driver in spring ClassNotFoundException: org.postgresql.Driver - ClassNotFoundException: org.postgresql.Driver 在 Spring Boot 中使用 PostgreSQL 驱动程序创建数据源时出现异常 - Exception when creating datasource with PostgreSQL driver in Spring Boot 如何解决无法在 spring-boot 应用程序中加载驱动程序 class: org.h2.Driver 的问题? - How to resolve unable to load driver class: org.h2.Driver in spring-boot application? Spring JPA - Postgres - 无法加载驱动程序 class:org.ZE4728F444B2428BC8E3F80ADF9 - Spring JPA - Postgres - Cannot load driver class: org.postgresql.Driver 使用 gradle 时,在 Spring 启动测试期间无法加载驱动程序类:“org.h2.Driver” - Cannot load driver class: "org.h2.Driver" during spring boot tests when using gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM