title: jdbc properties in Spring 3 using maven
body: <p>I am developing a maven multi-module projects in spring 3. I have two projects. I have one property file called jdbc.properties(it contains the database username, password) in Project A but project B doesn't have jdbc.properties . I have included project a as dependency in Project b to get some common code of Project a in Projet b. My question is how can i use properties of Project A jdbc.properties in Project b spring-context.xml file using maven </p>
  
  <p>application-context.xml (SNIPPET)</p>
  
  <pre><code>&lt;property name="jdbcUrl" value="${jdbc.url}"/&gt;
   &lt;property name="user" value="${jdbc.username}"/&gt;
   &lt;property name="password" value="${jdbc.password}"/&gt;
  </code></pre>
  
  <p>Here is a Structure of the my projects</p>
  
  <pre><code>**Projects**
   - Project A
  src/main/java
    +src/main/resource
      -Database.properties
      Database file has following properties 
      jdbc.driverClassName=org.h2.Driver
      jdbc.url=jdbc:h2:tcp://localhost/~/tododb
      jdbc.username=sa
      jdbc.password=
      jpa.database=H2
      jpa.showSql=true
      pom.xml
  
   - Project b
    +src/main/java
    src/main/resource (don't want to have jdbc.properties file in this project)
    pom.xml (I have added Project as dependencies in Project B because 
    i am using some  common classes of project a in project b) 
  </code></pre>
  
  <p>Here is POM files for both projects
      <strong>POM Configuration for both Projects</strong></p>
  
  <pre><code> - Project A (pom.xml)
    &lt;parent&gt;
      &lt;groupId&gt;com.ambientideas&lt;/groupId&gt;
      &lt;artifactId&gt;sample08-multimodulejava-parent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;com.ambientideas1&lt;/groupId&gt;
    &lt;artifactId&gt;sample-multimodulejava-module1&lt;/artifactId&gt;
    &lt;name&gt;sample application 1&lt;/name&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt; 
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/project&gt;
  
   - Project B (Pom.xml)
    &lt;parent&gt;
      &lt;groupId&gt;com.ambientideas&lt;/groupId&gt;
      &lt;artifactId&gt;sample08-multimodulejava-parent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;/parent&gt;
    &lt;artifactId&gt;sample-multimodulejava-module2&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt; 
  &lt;dependencies&gt; (using Project a common classes in project b)
          &lt;dependency&gt;
              &lt;groupId&gt;com.ambientideas1&lt;/groupId&gt;
              &lt;artifactId&gt;sample-multimodulejava-module1&lt;/artifactId&gt;
              &lt;version&gt;${version}&lt;/version&gt;
          &lt;/dependency&gt;
  &lt;/dependencies&gt; 
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is the both jdbc-context.jdbc files of Spring configuration of my projects.
      <strong>Now Spring Configuration</strong></p>
  
  <pre><code>In Both Projects (Project a, Project b), i have two jdbc.content.xml files( Spring xml's)
  
  &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
  &lt;context:property-placeholder location="/META-INF/classes/jdbc.properties" /&gt; 
      &lt;property name="driverClass" value="${jdbc.driverClassName}"/&gt;
          &lt;property name="jdbcUrl" value="${jdbc.url}"/&gt;
          &lt;property name="user" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt;
          &lt;/bean&gt; 
  </code></pre>
  
  <p>Question:
           I don't want to have to two database.proprties files in project A and Project b. What i want is that i Just want to have only one jdbc.properties file in project A, and then want to use properties of JDBC.propties file of Project A in  Project B.  </p>
  
  <pre><code>    &lt;property name="driverClass" value="${jdbc.driverClassName}"/&gt;
          &lt;property name="jdbcUrl" value="${jdbc.url}"/&gt;
          &lt;property name="user" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt;
          &lt;/bean&gt;
  </code></pre>
  
  <p>Is there any way to do it? Here is stricture of Project B pom.xml</p>
  
  <pre><code>    &lt;project&gt;
      &lt;parent&gt;
      &lt;groupId&gt;com.ambientideas&lt;/groupId&gt;
      &lt;artifactId&gt;sample08-multimodulejava-parent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;/parent&gt;
      &lt;artifactId&gt;sample-multimodulejava-module2&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt; 
      &lt;dependencies&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;com.ambientideas1&lt;/groupId&gt;
      &lt;artifactId&gt;sample-multimodulejava-module1&lt;/artifactId&gt;
      &lt;version&gt;${version}&lt;/version&gt;
      &lt;description&gt;Project B&lt;description&gt;
  &lt;/dependency&gt;
      &lt;/dependencies&gt; 
      &lt;/project&gt;
  </code></pre>
  
  <p>Thanks in Advance.</p>