title: Spring database configuration issue
body: <p>I am new to <code>Spring-MVC</code>, i am trying to create a <code>Spring-MVC</code> project that uses <code>annotation</code> in <code>controller</code> and also creates <code>databases</code>.</p>
  
  <p>The application works fine, when i write all the <code>xml</code> code in <code>spring-dispatcher-servlet.xml</code> file, but when i separate <code>spring database connection xml</code> and <code>spring servlet xml</code> file, it stops working.</p>
  
  <p>The following code successfully creates tables in database, but it fails to load controllers, it gives me <code>404 not found</code> page when i try to hit any controller.
  If i comment <code>&lt;listner&gt;</code> code in my <code>web.xml</code> file it successfully loads all the controllers, but no database operations performed.</p>
  
  <p>Kindly guide me what i am doing wrong here.</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;!--  JPA  --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
  &lt;!--  Servlet Dispatcher  --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;default&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p><strong>Spring.xml</strong></p>
  
  <pre><code>    &lt;mvc:annotation-driven /&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.evantage.models" /&gt;
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/springDB" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="" /&gt;
      &lt;/bean&gt;
      &lt;!-- This produces a container-managed EntityManagerFactory; rather than 
          application-managed EntityManagerFactory as in case of LocalEntityManagerFactoryBean --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/&gt;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="persistenceUnitName" value="persistenceUnit"/&gt;
          &lt;property name="persistenceXmlLocation" value="/WEB-INF/persistence.xml" /&gt;
      &lt;/bean&gt;
  
  
  
     &lt;jpa:repositories base-package="com.evantagesoft.springmvctiles.repository"
                        entity-manager-factory-ref="entityManagerFactory"
                        transaction-manager-ref="transactionManager"/&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Spring-dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;context:component-scan base-package="com.evantage.controllers" /&gt;
   &lt;mvc:annotation-driven /&gt; 
  &lt;bean id="tilesConfigurer"
      class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
      &lt;property name="definitions"&gt;
          &lt;list&gt;
              &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="preparerFactoryClass"
          value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- View Handler --&gt;
  &lt;bean
      class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
      &lt;property name="favorPathExtension" value="true" /&gt;
      &lt;property name="mediaTypes"&gt;
          &lt;map&gt;
              &lt;entry key="xml" value="text/xml" /&gt;
              &lt;entry key="json" value="application/json" /&gt;
              &lt;entry key="html" value="text/html" /&gt;
              &lt;entry key="less" value="text/html" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
      &lt;property name="viewResolvers"&gt;
          &lt;list&gt;
              &lt;bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
                  &lt;property name="viewClass"
                      value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
              &lt;/bean&gt;
              &lt;bean
                  class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                  &lt;!-- &lt;property name="prefix" value="/"/&gt; --&gt;
                  &lt;property name="prefix"&gt;
                      &lt;value&gt;/WEB-INF/&lt;/value&gt;
                  &lt;/property&gt;
                  &lt;property name="suffix"&gt;
                      &lt;value&gt;.jsp&lt;/value&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>