title: no bean named "userDao" is defined
body: <p>I got this exception. This is my code:</p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:/servlet-context.xml");
  UserDao userDao = (UserDao) context.getBean("userDao");
  </code></pre>
  
  <p>And this is my servlet-context.xml file located in /myproject/WebContent/WEB-INF/spring/appServlet/servlet-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
      &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="userDao" class="it.ex.home.dao.JdbcUserDao"&gt;
          &lt;beans:property name="dataSource" ref="dataSource"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;beans:property name="url" value="jdbc:mysql://localhost:3306/hibernate_db"/&gt;
          &lt;beans:property name="username" value="root"/&gt;
          &lt;beans:property name="password" value="root"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;context:component-scan base-package="it.ex.home" /&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>How can I fix this? </p>