title: Spring project how do I access JBoss JNDI Datasources
body: <p>Below is my current database.xml file for my Spring Project. Can someone please tell me what would have to be changed so I can use a JBoss JNDI datasource in it.. I want to do this so I don't need the config files with the database user and password and url in it.</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:context="http://www.springframework.org/schema/context"
         xmlns:tx="http://www.springframework.org/schema/tx" 
         xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
                              http://www.springframework.org/schema/beans/spring-beans.xsd
                              http://www.springframework.org/schema/context 
                              http://www.springframework.org/schema/context/spring-context-3.1.xsd
                              http://www.springframework.org/schema/tx
                              http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                              http://www.springframework.org/schema/jdbc
                              http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"&gt;
  
                              &lt;!-- 
  
       Last changed: $LastChangedDate: 2012-11-19 08:53:13 -0500 (Mon, 19 Nov 2012) $
       @author $Author: johnathan.smith@uftwf.org $
       @version $Revision: 829 $
  
      --&gt;
  
      &lt;context:property-placeholder location="classpath:app.properties" /&gt;
  
      &lt;context:component-scan base-package="org.uftwf" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
  
  
  
      &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close"&gt;
  
          &lt;!-- these are C3P0 properties      --&gt; 
          &lt;property name="acquireIncrement" value="${database.c3p0.acquireIncrement}" /&gt;
          &lt;property name="minPoolSize" value="${database.c3p0.minPoolSize}" /&gt;
          &lt;property name="maxPoolSize" value="${database.c3p0.maxPoolSize}" /&gt;
          &lt;property name="maxIdleTime" value="${database.c3p0.maxIdleTime}" /&gt;
          &lt;property name="maxIdleTimeExcessConnections" value="${database.c3p0.maxIdleTimeExcessConnections}" /&gt;
          &lt;property name="numHelperThreads" value="${database.c3p0.numHelperThreads}" /&gt;
          &lt;property name="unreturnedConnectionTimeout" value="${database.c3p0.unreturnedConnectionTimeout}" /&gt;
          &lt;property name="idleConnectionTestPeriod" value="300" /&gt;
  
          &lt;property name="driverClass" value="${database.driver}" /&gt;
          &lt;property name="jdbcUrl" value="${database.url}" /&gt;
          &lt;property name="user" value="${database.user}" /&gt;
          &lt;property name="password" value="${database.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;org.uftwf.enrollment.model.Contact&lt;/value&gt;
                  &lt;value&gt;org.uftwf.enrollment.model.Enrollment&lt;/value&gt;
                  &lt;value&gt;org.uftwf.enrollment.model.Member&lt;/value&gt;
                  &lt;value&gt;org.uftwf.enrollment.model.Profile&lt;/value&gt;
                  &lt;value&gt;org.uftwf.enrollment.model.School&lt;/value&gt;
  
              &lt;/list&gt;
          &lt;/property&gt;
  
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;${hibernate.use_sql_comments}&lt;/prop&gt;
                  &lt;prop key="format_sql"&gt;${format_sql}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="hibernateTransactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>