Wednesday, July 17, 2019

[google-cloud-sql-discuss] Re: Spring JPA applicationContext.xml for Google Cloud SQL Postgres

You can connect via Cloud Proxy or through private IP. For private IP, you need to enable / check if VPC native is enabled for your GKE. 

On Tuesday, July 16, 2019 at 3:44:15 PM UTC+2, Aniket Bhadane wrote:
I want to connect to Google Cloud SQL Postgres using my Spring 4 application running on GKE using JPA. Previously, my applicationContext.xml which connected to database on a container in the same pod as application, contained:


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
 
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>


<bean id="entityManagerFactory"
 
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 
<property name="dataSource" ref="dataSource" />
 
<property name="packagesToScan" value="com.avaya.myproject.entity" />
 
<property name="jpaVendorAdapter" ref="hbAdapterBean_pgsql"/>
 
<property name="jpaProperties">
 
<props>
 
<prop key="hibernate.show_sql">false</prop>
 
<prop key="hibernate.format_sql">true</prop>
 
<prop key="hibernate.hbm2ddl.auto">update</prop>
 
<prop key="hibernate.id.new_generator_mappings">true</prop>
 
</props>
 
</property>
</bean>


<bean id="hbAdapterBean_pgsql" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
 
<property name="showSql" value="false"></property>  
 
<property name="generateDdl" value="true"></property>  
 
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"></property>  
</bean>  


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
 
<property name="driverClassName" value="org.postgresql.Driver"></property>  
 
<property name="url" value="jdbc:postgresql://${DB_HOST_}:${DB_PORT_}/${DB_NAME_}"></property>  
 
<property name="username" value="${DB_USER_}"></property>  
 
<property name="password" value="${DB_PASSWORD_}"></property>  
</bean>
 
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 
<constructor-arg ref="dataSource"/>
</bean>


I'm struggling to figure out what changes are required in the xml for connecting with Google Cloud SQL Postgres.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/39390604-7cf9-4f04-b51e-ce3410eadec7%40googlegroups.com.

No comments:

Post a Comment