title: How to configure controller in spring without component scanning in xml?
body: <p>I have to design a very large scale project for a bank using spring mvc. I already choose to go with the XML configuration. My concern is to limit the start up time of the server. There will be approximately 2000 controllers.</p>
  
  <p>I already use component scan for scanning the <code>@Controller</code>. It worked fine. But, the problem is when I remove the component scan from XML and add the controller bean using bean configuration manually in XML, it didn't create the instance of controller in IOC container. And gives me the 404 not found error. So how can I configure the controller without component scanning in XML.</p>
  
  <p>Followings are my code samples. Any help?</p>
  
  <p><strong>servlet-context.xml</strong></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:mvc="http://www.springframework.org/schema/mvc"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          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.xsd"&gt;
  
      &lt;context:annotation-config/&gt;
  
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;!--&lt;context:component-scan base-package="" /&gt;--&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>root-context.xml</strong></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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;import resource="dataContext/data-context.xml" /&gt;
  
      &lt;bean id="contactSetupController" class="com.stl.afs.ci.cca.controller.ContactSetupController"&gt;
          &lt;property name="contactSetupDao" ref="contactSetupDao" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="contactSetupDao" class="com.stl.afs.ci.cca.controller.ContactSetupDao" scope="prototype"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>ContactSetupController.java</strong></p>
  
  <pre><code>package com.stl.afs.ci.cca.controller;
  
  import org.hibernate.Query;
  import org.hibernate.SessionFactory;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Lazy;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  
  @Controller
  @RequestMapping("/contactsetup")
  public class ContactSetupController {
      private static final Logger logger = LoggerFactory.getLogger(ContactSetupController.class);
  
  
      private ContactSetupDao contactSetupDao;
  
      public void setContactSetupDao(ContactSetupDao contactSetupDao) {
          this.contactSetupDao = contactSetupDao;
      }
  
      @RequestMapping(method = RequestMethod.GET)
      public String index(ModelMap model) {
          contactSetupDao.showDepedency();
  
          model.addAttribute("message", "Hello world! Nice to see you in the planet");
          return "ci/contactsetup/index";
      }
  }
  </code></pre>
  
  <p><strong>ContactSetupDao.java</strong></p>
  
  <pre><code>package com.stl.afs.ci.cca.controller;
  
  import org.hibernate.Query;
  import org.hibernate.SessionFactory;
  import org.springframework.transaction.annotation.Transactional;
  
  import java.util.List;
  
  /**
   * Created by ARNAB on 1/8/2015.
   */
  public class ContactSetupDao {
      public ContactSetupDao() {
          System.out.println("------DAO------");
      }
  
      private SessionFactory sessionFactory;
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@" + sessionFactory);
          this.sessionFactory = sessionFactory;
      }
  
      @Transactional(readOnly = true)
      public void showDepedency(){
          Query query = sessionFactory.getCurrentSession().createSQLQuery("SELECT * FROM customers");
          int i = 0;
          for (Object o : query.list()) {
              i++;
          }
          System.out.println(i);
      }
  
  }
  </code></pre>