Поэтому я пытался подключить мое приложение Spring Boot (в Google App Engine) к облаку SQL (Postgresql) и получал следующие ошибки:
A 2020-03-15T04:58:41.951800182Z org.postgresql.util.PSQLException: The connection attempt failed.
A 2020-03-15T04:58:41.951800183Z at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:272) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800184Z at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800185Z at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:215) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800186Z at org.postgresql.Driver.makeConnection(Driver.java:404) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800187Z at org.postgresql.Driver.connect(Driver.java:272) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800188Z at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.23.jar!/:na]
A 2020-03-15T04:58:41.951800189Z at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.23.jar!/:na]
A 2020-03-15T04:58:41.951800190Z at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735) [tomcat-jdbc-8.5.23.jar!/:na]
A 2020-03-15T04:58:41.951800191Z at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667) [tomcat-jdbc-8.5.23.jar!/:na]
A 2020-03-15T04:58:41.951800192Z at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482) [tomcat-jdbc-8.5.23.jar!/:na]
A 2020-03-15T04:58:41.951800193Z at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.23.jar!/:na]
...
A 2020-03-15T04:58:41.951800269Z Caused by: java.net.SocketException: already connected
A 2020-03-15T04:58:41.951800270Z at java.net.Socket.connect(Socket.java:569) ~[na:1.8.0_222]
A 2020-03-15T04:58:41.951800271Z at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) ~[na:1.8.0_222]
A 2020-03-15T04:58:41.951800272Z at org.postgresql.core.PGStream.<init>(PGStream.java:61) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800273Z at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144) ~[postgresql-9.4.1212.jre7.jar!/:9.4.1212.jre7]
A 2020-03-15T04:58:41.951800274Z ... 85 common frames omitted
Не удалось не понимаю, что означает "java. net .SocketException: уже подключено"
Вот мой файл конфигурации в application.properties:
spring.datasource.url=${URL}
spring.datasource.username=${USER}
spring.datasource.password=${PASSWORD}
spring.datasource.driverClassName=org.postgresql.
spring.cloud.gcp.sql.enabled=true
spring.cloud.gcp.projectId={projectId}
spring.cloud.gcp.sql.instanceName={projectId}:{region}:{instanceName}
spring.cloud.gcp.sql.jdbcUrl=jdbc:postgresql://google/{dbname}?cloudSqlInstance={projectId}:{region}:{dbname}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user={user}&password={password}
spring.cloud.gcp.sql.databaseName={DBname}
spring.cloud.gcp.sql.userName={user}
spring.cloud.gcp.sql.password={password}
spring.cloud.gcp.sql.jdbcDriver=org.postgresql.Driver
spring.cloud.gcp.sql.instance-connection-name={projectId}:{region}:{instanceName}
spring.cloud.gcp.sql.database-name={DBname}
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.generate-ddl=true
А вот мой Файл конфигурации app.yaml:
runtime: java
env: flex
runtime_config:
jdk: openjdk8
env_variables:
SPRING_PROFILES_ACTIVE: "gcp,postgresql"
URL: "jdbc:postgresql://google/{dbName}?cloudSqlInstance={projectId}:{region}:{instanceName}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user={user}&password={password}"
USER: "{user}"
PASSWORD: "{password}"
beta_settings:
cloud_sql_instances: "{projectId}:{region}:{instanceName}"
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
resources:
cpu: 2
memory_gb: 2.3
disk_size_gb: 10
volumes:
- name: ramdisk1
volume_type: tmpfs
size_gb: 0.5
Облачная SQL конфигурация опубликована c IP. Буду признателен за любые идеи о том, что я могу делать неправильно?