SHARE
TWEET

Untitled

a guest Jun 18th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. spring:
  2.   jpa:
  3. database-platform: org.hibernate.dialect.PostgreSQL95Dialect
  4. properties:
  5.   hibernate:
  6.     default_schema: {schema}
  7.     dialect : org.hibernate.dialect.PostgreSQL95Dialect
  8. datasource:
  9.   username: {username}
  10.   password: {pwd}
  11. cloud:
  12.   gcp:
  13.     sql:
  14.       database-name: {dbname}
  15.       instance-connection-name: {connection-name}
  16.      
  17. <dependency>
  18.     <groupId>org.springframework.boot</groupId>
  19.     <artifactId>spring-boot-starter-data-jpa</artifactId>
  20. </dependency>
  21. <dependency>
  22.     <groupId>org.springframework.cloud</groupId>
  23.     <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
  24. </dependency>
  25.      
  26. @Bean(name = "dataSourceGenerix")
  27. public DataSource dataSourceGenerix() {
  28.     final DriverManagerDataSource dataSource = new DriverManagerDataSource();
  29.  
  30.     dataSource.setDriverClassName(generixDatasourceDriver);
  31.     dataSource.setUrl(generixDatasourceUrl);
  32.     dataSource.setUsername(generixDatasourceUsername);
  33.     dataSource.setPassword(generixDatasourcePassword);
  34.     return dataSource;
  35. }
  36.  
  37. @Bean
  38. public NamedParameterJdbcTemplate jdbcTemplateGenerix(@Qualifier("dataSourceGenerix") DataSource dataSourceGenerix) {
  39.     NamedParameterJdbcTemplate jdbcTemplate = null;
  40.  
  41.     try(Connection conn = DataSourceUtils.getConnection(dataSourceGenerix)) {
  42.         jdbcTemplate = new NamedParameterJdbcTemplate(dataSourceGenerix);
  43.     } catch (SQLException | CannotGetJdbcConnectionException e) {
  44.         log.error("{} {} : {}", Constantes.NO_DB_CONNECTION_GENERIX, generixDatasourceUrl, e.getMessage());
  45.     }
  46.     return jdbcTemplate;
  47. }
  48.      
  49. @Bean
  50. @Primary
  51. DataSource dataSource() {
  52.     DriverManagerDataSource dataSource = new DriverManagerDataSource();
  53.  
  54.     dataSource.setUrl("jdbc:postgresql://google/{dbname}?cloudSqlInstance={instancename}&socketFactory=com.google.cloud.sql.postgres.SocketFactory");
  55.     dataSource.setUsername({username});
  56.     dataSource.setPassword({pwd});
  57.  
  58.     return dataSource;
  59. }
  60.      
  61. c.g.cloud.sql.core.SslSocketFactory : Obtaining ephemeral certificate for Cloud SQL instance [{instancename}].
  62. o.s.b.a.orm.jpa.DatabaseLookup      : Unable to determine jdbc url from datasource
  63. org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException:
  64. Caused by: java.lang.RuntimeException: Unable to retrieve information about Cloud SQL instance
  65. Caused by: java.net.SocketTimeoutException: connect timed out
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top