how to make database configuration configurable of persistance.xml file through database.properties file
<p>I would like to get confirmation on the query "Is there any way to make database configurations configuration through database.properties using in <code>persistance.xml</code>". Is the below possible?</p>

<p>My following configuration works absolutely fine, </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
    &lt;persistence-unit name="spring-data-jpa-krishna" transaction-type="RESOURCE_LOCAL"&gt;
        &lt;class&gt;net.javabeat.springdata.model.Address&lt;/class&gt;
        &lt;class&gt;net.javabeat.springdata.model.Employee&lt;/class&gt;

        &lt;properties&gt;
            &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test" /&gt;
            &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
            &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
            &lt;property name="javax.persistence.jdbc.password" value="root" /&gt;

            &lt;property name="hibernate.show_sql" value="true" /&gt;
            &lt;property name="eclipselink.logging.level" value="FINE" /&gt;
            &lt;property name="eclipselink.ddl-generation" value="create-tables" /&gt;
        &lt;/properties&gt;
    &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</code></pre>

<p>but I've many environment to deploy the application codes like Dev, QA, UAT, SAT, SystemTest etc, so I wanted to make configuration like below<br>
database.properties:</p>

<pre><code>mysql.jdbc.driver.class=com.mysql.jdbc.Driver
mysql.jdbc.url=jdbc:mysql://localhost:3306/test
mysql.jdbc.username=root
mysql.jdbc.password=root
hibernate.show_sql=true
eclipselink.logging.level=FINE
eclipselink.ddl-generation=create-tables
</code></pre>

<p>persistence.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
    &lt;persistence-unit name="spring-data-jpa-krishna" transaction-type="RESOURCE_LOCAL"&gt;
        &lt;class&gt;net.javabeat.springdata.model.Address&lt;/class&gt;
        &lt;class&gt;net.javabeat.springdata.model.Employee&lt;/class&gt;

        &lt;properties&gt;
            &lt;property name="javax.persistence.jdbc.url" value="${mysql.jdbc.url}" /&gt;
            &lt;property name="javax.persistence.jdbc.driver" value="${mysql.jdbc.driver.class}" /&gt;
            &lt;property name="javax.persistence.jdbc.user" value="${mysql.jdbc.username}" /&gt;
            &lt;property name="javax.persistence.jdbc.password" value="${mysql.jdbc.password}" /&gt;

            &lt;property name="hibernate.show_sql" value="${hibernate.show_sql}" /&gt;
            &lt;property name="eclipselink.logging.level" value="${eclipselink.logging.level}" /&gt;
            &lt;property name="eclipselink.ddl-generation" value="eclipselink.ddl-generation" /&gt;
        &lt;/properties&gt;
    &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</code></pre>

<p>This would help me to solve my overhead. But I wonder how <code>persistece.xml</code> would load <code>database.properties</code> in order to get <strong>placeholders</strong> properly?</p>

<p>This <a href="https://stackoverflow.com/questions/3935394/how-to-externalize-properties-from-jpas-persistence-xml">How to externalize properties from JPAs persistence.xml?</a> link has done it through JNDI, but I simply wanted to do it through database.properties file.</p>

<p>Edit-1:
Yes, I'm using spring-Context.xml file</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
        http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;

    &lt;!-- For consider the using of annotations foe defining Spring Bean --&gt;
    &lt;context:annotation-config /&gt;

    &lt;!-- For defining Spring Bean --&gt;
    &lt;context:component-scan base-package="net.javabeat.springdata.beans" /&gt;

    &lt;!-- For bootstrapping the Spring Repository --&gt;
    &lt;jpa:repositories base-package="net.javabeat.springdata.repository" /&gt;

    &lt;!-- Necessary to get the entity manager injected into the factory bean --&gt;
    &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;

    &lt;bean id="registrationBean" class="net.javabeat.springdata.beans.RegistrationBean" /&gt;


    &lt;!-- =======  WAY-1    ========= --&gt;
    &lt;!-- ===== Define EclipseLink JPA Vendor Adapter ===== --&gt;
    &lt;bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"&gt;
        &lt;property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" /&gt;
        &lt;property name="generateDdl" value="false" /&gt;
        &lt;property name="showSql" value="true" /&gt;
    &lt;/bean&gt;

    &lt;!-- Entity Manager Factory --&gt;
    &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
        =========== Read persistent.xml file from here  ===========
        &lt;property name="persistenceUnitName" value="spring-data-jpa-krishna" /&gt;
        &lt;property name="jpaVendorAdapter" ref="jpaVendorAdapter" /&gt;
        &lt;!-- spring based scanning for entity classes--&gt;
        &lt;property name="packagesToScan" value="net.javabeat.springdata.*" /&gt;
    &lt;/bean&gt; 

    &lt;!-- 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;!-- Enable Transactional Manner --&gt;
    &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

&lt;/beans&gt;
</code></pre>

<p><strong>Edit-1: I see below error now:</strong></p>

<pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.javabeat.springdata.repository.EmployeeRepository net.javabeat.springdata.beans.RegistrationBean.employeeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Cannot create inner bean '(inner bean)#5d3c9c43' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5d3c9c43': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [SpringContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: PersistenceProvider [org.eclipse.persistence.jpa.PersistenceProvider@6201c010] did not return an EntityManagerFactory for name 'spring-data-jpa-krishna'
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 13 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Cannot create inner bean '(inner bean)#5d3c9c43' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5d3c9c43': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [SpringContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: PersistenceProvider [org.eclipse.persistence.jpa.PersistenceProvider@6201c010] did not return an EntityManagerFactory for name 'spring-data-jpa-krishna'
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1475)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1220)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 15 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5d3c9c43': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [SpringContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: PersistenceProvider [org.eclipse.persistence.jpa.PersistenceProvider@6201c010] did not return an EntityManagerFactory for name 'spring-data-jpa-krishna'
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1117)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1012)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
    ... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [SpringContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: PersistenceProvider [org.eclipse.persistence.jpa.PersistenceProvider@6201c010] did not return an EntityManagerFactory for name 'spring-data-jpa-krishna'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 36 more
Caused by: java.lang.IllegalStateException: PersistenceProvider [org.eclipse.persistence.jpa.PersistenceProvider@6201c010] did not return an EntityManagerFactory for name 'spring-data-jpa-krishna'
    at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:90)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
    ... 43 more
</code></pre>

<p>I made changes in pom.xml file:</p>

<pre><code>&lt;build&gt;
        &lt;pluginManagement&gt;
            &lt;plugins&gt;
                &lt;plugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                    &lt;version&gt;3.1&lt;/version&gt;
                    &lt;configuration&gt;
                        &lt;source&gt;${java.version}&lt;/source&gt;
                        &lt;target&gt;${java.version}&lt;/target&gt;
                    &lt;/configuration&gt;
                &lt;/plugin&gt;
            &lt;/plugins&gt;
        &lt;/pluginManagement&gt;
        &lt;!-- &lt;filters&gt;
            &lt;filter&gt;database.properties&lt;/filter&gt;    
        &lt;/filters&gt; --&gt;
        &lt;resources&gt;
            &lt;resource&gt;
                &lt;directory&gt;src/main/resources&lt;/directory&gt;
            &lt;/resource&gt;
        &lt;/resources&gt;
    &lt;/build&gt;
</code></pre>

<p>persistence.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
    &lt;persistence-unit name="spring-data-jpa-krishna" transaction-type="RESOURCE_LOCAL"&gt;
        &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
        &lt;class&gt;net.javabeat.springdata.model.Address&lt;/class&gt;
        &lt;class&gt;net.javabeat.springdata.model.Employee&lt;/class&gt;

        &lt;!-- http://docs.oracle.com/cd/E16439_01/doc.1013/e13981/cfgdepds005.htm --&gt;
        &lt;properties&gt;        
            &lt;property name="javax.persistence.jdbc.url" value="${jdbc.mysql.url}" /&gt;
            &lt;property name="javax.persistence.jdbc.driver" value="${jdbc.mysql.driver.class}" /&gt;
            &lt;property name="javax.persistence.jdbc.user" value="${jdbc.mysql.username}" /&gt;
            &lt;property name="javax.persistence.jdbc.password" value="${jdbc.mysql.password}" /&gt;

            &lt;property name="eclipselink.logging.level" value="FINE" /&gt;
            &lt;property name="eclipselink.ddl-generation" value="create-tables" /&gt;
        &lt;/properties&gt;
    &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</code></pre>