<p>Hi i receive the following error:</p>

<blockquote>
  <p>Exception encountered during context initialization - cancelling
  refresh attempt:
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'entityManagerFactory' defined in class path
  resource [file.xml]: Invocation of init method failed; nested
  exception is org.hibernate.service.spi.ServiceException: Unable to
  create requested service
  [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]</p>
</blockquote>

<p>I have a kubernetes cluster where I defined a pod with two containers, one is the postgres db and the other one is a java rest-api application. I'm unable to connect to the db from the application. I'm tring to connect to the postgres db using spring, this is my xml file configuration:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;!-- JPA Transaction Manager --&gt;
&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
&lt;/bean&gt;

&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
    &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
    &lt;property name="url" value="jdbc:postgresql://localhost:5432/dbName" /&gt;
    &lt;property name="username" value="postgres"/&gt;
    &lt;property name="password" value="postgres"/&gt;
&lt;/bean&gt;

&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="packagesToScan" value="com.my-package.it.name.db" /&gt;
    &lt;property name="jpaVendorAdapter"&gt;
        &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
            &lt;!--&lt;property name="showSql" value="true" /&gt;--&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="jpaDialect"&gt;
        &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /&gt;
    &lt;/property&gt;
&lt;/bean&gt;

</code></pre>

<p>Well thanks for your time and help</p>

lello-sca87
<p>What you should do is, create deployment for your database and then service, which targets this deployment and then ping using this service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: postgres
</code></pre>

<p>If you want me to reproduce it on your files, please provide it in your post.
You can check this <a href="https://blog.nebrass.fr/playing-with-spring-boot-on-kubernetes/" rel="nofollow noreferrer">article</a>.</p>
