简体   繁体   English

使用远程 PostgreSQL Db 将 Spring-Boot 应用程序部署到远程服务器的问题

[英]Problem to deploy Spring-Boot Application to Remote server with remote PostgreSQL Db

I have spring-boot app woth application-properties:我有具有应用程序属性的 spring-boot 应用程序:

spring.jpa.database=postgresql
spring.jpa.show-sql=true

server.port=${PORT:8080}

spring.datasource.driverClassName=org.postgresql.Driver
spring.sql.init.platform=postgres
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://1**.1**.**.**6:****/dbname  # server address
spring.datasource.username=n******
spring.datasource.password=p********
spring.jpa.hibernate.ddl-auto=update

and in my local computer i use:在我的本地计算机中,我使用:

scp -P 1111 D:\user-home\test-0.0.1-SNAPSHOT.jar user@111.111.11.111:/home/user

and then of course然后当然

java -jar test-0.0.1-SNAPSHOT.jar

and I have我有

org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315) ~[postgresql-42.2.22.jar!/:42.2.22]
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.22.jar!/:42.2.22]
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.22.jar!/:42.2.22]
        at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.22.jar!/:42.2.22]
        at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.22.jar!/:42.2.22]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

My postres in pom:我在 pom 中的 postres:

<dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.22</version>
        </dependency>

PASTEBIN Here is full console view with error. PASTEBIN这是带有错误的完整控制台视图。 None of the solutions found work.没有一个解决方案找到工作。 Does anyone have a solution for this problem?有没有人有这个问题的解决方案?

It looks like whichever server you are running the jar from is not able to access the database server on that port.看起来您运行 jar 的任何服务器都无法访问该端口上的数据库服务器。 You should check to make sure that the firewall on both sides is configured correctly (JAR server allows traffic out on the database port and the database server allows traffic in on the database port from the JAR server's IP address).您应该检查以确保双方的防火墙配置正确(JAR 服务器允许流量从数据库端口流出,而数据库服务器允许流量从 JAR 服务器的 IP 地址流入数据库端口)。

You can test the connectivity using telnet by running the command telnet <database-ip> <port> eg telnet 123.123.123.123 9876 from the JAR server (assuming telnet is available).您可以通过从 JAR 服务器运行命令telnet <database-ip> <port>例如telnet 123.123.123.123 9876 (假设 telnet 可用)来使用 telnet 测试连接。 If it is able to establish a connection, then running the JAR should be able to run again and connect to the database.如果能够建立连接,那么运行 JAR 应该能够再次运行并连接到数据库。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM