title: How To Configure MySQL DataSource In Tomcat 7 using hibernate and spring?
body: <p>this is my problem: Im trying to configure my data source in context.xml tom cat's field, as follow:</p>
  
  <pre><code>//C:\apache-tomcat-7.0.42\conf\context.xml 
  
  &lt;Context&gt;
  
  &lt;!-- Default set of monitored resources --&gt;
  &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
  
  
  &lt;Resource
    name="jdbc/myDB" docBase="inv" auth="Container"
    type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
    maxActive="100" maxIdle="30" maxWait="10000"
    url="jdbc:mysql://localhost:3306/myDB?autoReconnect=true"
    username="root" password="pass"/&gt;
  
  &lt;/Context&gt;
  </code></pre>
  
  <p>And I have in my servlet-context.xml (spring project) the configuration of hibernate:</p>
  
  <pre><code>...
  &lt;!-- JDBC Data Source --&gt;
  &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/rhcimax"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="1234"/&gt;
      &lt;property name="validationQuery" value="SELECT 1"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate Session Factory --&gt;
  &lt;bean id="mySessionFactory"     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="packagesToScan"&gt;
      &lt;array&gt;
          &lt;value&gt;com.blah.baseProject&lt;/value&gt;
      &lt;/array&gt;
  &lt;/property&gt;
  &lt;property name="hibernateProperties"&gt;
    &lt;value&gt;
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
    &lt;/value&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate Transaction Manager --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
  &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Activates annotation based transaction management --&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  </code></pre>
  
  <p>What can I do to delete the following part of the code and delegate it to tom cat's context.xml?:</p>
  
  <pre><code>&lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/rhcimax"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="1234"/&gt;
      &lt;property name="validationQuery" value="SELECT 1"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><strong>FINAL SOLUTION:</strong> </p>
  
  <p>The references are:  xmlns:jee="http://www.springframework.org/schema/jee", xsi:schemaLocation="http://www.springframework.org/schema/jee <a href="http://www.springframework.org/schema/jee/spring-jee.xsd" rel="nofollow">http://www.springframework.org/schema/jee/spring-jee.xsd</a>"</p>
  
  <p>Finally we have:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd"&gt;
  
  &lt;jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/myDB"/&gt;
  
  &lt;!-- Hibernate Session Factory --&gt;
  &lt;bean id="mySessionFactory"     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="packagesToScan"&gt;
      &lt;array&gt;
          &lt;value&gt;com.blah.baseProject&lt;/value&gt;
      &lt;/array&gt;
  &lt;/property&gt;
  &lt;property name="hibernateProperties"&gt;
    &lt;value&gt;
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
    &lt;/value&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate Transaction Manager --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
  &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Activates annotation based transaction management --&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  </code></pre>
  
  <p>Thanks alanstroop.</p>
  
  <p>More information: <a href="http://static.springsource.org/spring/docs/3.3.0.BUILD-SNAPSHOT/spring-framework-reference/html/xsd-config.html" rel="nofollow">http://static.springsource.org/spring/docs/3.3.0.BUILD-SNAPSHOT/spring-framework-reference/html/xsd-config.html</a></p>