title: Maven Profiles, Spring, JDBC and JNDI Datasources
body: <p>I have a Spring project that uses Maven and has several profiles to allow it to run on different setups with resource filtering. Some of the setups have JNDI and some do not. For the ones that do not a JDBC data source is required.</p>
  
  <p>What is the best way to handle this given my setup? I want to avoid doing anything with multiple files and ant-run or anything like that. Which leaves me with:</p>
  
  <ul>
  <li>Setting up two beans and filtering my resources to include one or the other.</li>
  <li>Something I haven't thought of?</li>
  </ul>
  
  <p>Here's an example of the first bullet:</p>
  
  <pre><code>&lt;bean id="jdbcDataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close"
      p:driverClassName="${jdbc.driver}"
      p:url="${jdbc.url}"
      p:username="${jdbc.username}"
      p:password="${jdbc.password}"/&gt;
  
  &lt;bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
      p:jndiName="${jndi.name}" /&gt;
  
  &lt;bean id="someBean" class="com.whatever.SomeBeanImpl"
      p:dataSource-ref="${dataSource}"/&gt;
  </code></pre>
  
  <p>I'm interested to hear of other ways people have accomplished this and why they went with that solution. Or if they went with this solution and why.</p>