title: how to resolve spring no bean named 'dataSource' is defined?
body: <p>my 'dataSource' bean is defined in dao-context.xml, like this</p>
  
  <pre><code>&lt;bean name="hcpDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" &gt;
                  &lt;property name="driverClassName" value="${hcp.connection.driver_class}" /&gt;
                  &lt;property name="username" value="${hcp.connection.username}" /&gt;
                  &lt;property name="password" value="${hcp.connection.password}" /&gt;
                  &lt;property name="url" value="${hcp.connection.url}" /&gt;
                  &lt;property name="maxIdle" value="${hcp.minPoolSize}" /&gt;
                  &lt;property name="maxActive" value="${hcp.maxPoolSize}" /&gt;
              &lt;/bean&gt;
  </code></pre>
  
  <p>in security-context.xml i'm trying to use it like this:</p>
  
  <pre><code>&lt;beans:bean class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl" id="userDetailsService"&gt;
          &lt;beans:property name="rolePrefix" value="ROLE_"/&gt;
          &lt;beans:property name="dataSource" ref="dataSource"/&gt;
          &lt;beans:property name="usersByUsernameQuery" value="SELECT username,password,enabled FROM Users WHERE username = ?"/&gt;
          &lt;beans:property name="authoritiesByUsernameQuery" value="SELECT u.username, a.authorityname FROM Users u JOIN Users_Authorities ua on u.id = ua.user_id JOIN Authorities a on ua.authorities_id = a.id WHERE u.username = ?"/&gt;
      &lt;/beans:bean&gt;
  </code></pre>
  
  <p>And have error in logs:</p>
  
  <pre><code>2014-06-08 16:10:06,683 ERROR [localhost-startStop-1] ContextLoader - Context initialization failed
  
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService' defined in class path resource [HCP-security-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
  </code></pre>
  
  <p>this is my applicationContext.xml in the WEB-INF Folder:</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:tx="http://www.springframework.org/schema/tx" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:jee="http://www.springframework.org/schema/jee" 
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"&gt;
  
      &lt;import resource="classpath:HCP-security-context.xml" /&gt;
      &lt;import resource="classpath:HCP-service-context.xml" /&gt;
      &lt;import resource="classpath:HCP-dao-context.xml" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>and this is my web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt;
    &lt;display-name&gt;&lt;/display-name&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;
              org.springframework.web.context.request.RequestContextListener
          &lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;filter&gt;
          &lt;description&gt;
              generated-spring-security-session-integration-filter
          &lt;/description&gt;
          &lt;filter-name&gt;
              SpringSecuritySessionIntegrationFilter
          &lt;/filter-name&gt;
          &lt;filter-class&gt;
              org.springframework.security.web.context.SecurityContextPersistenceFilter
          &lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter&gt;
          &lt;description&gt;generated-spring-security-filter&lt;/description&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;
              org.springframework.web.filter.DelegatingFilterProxy
          &lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;
              SpringSecuritySessionIntegrationFilter
          &lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
    &lt;filter&gt;
      &lt;description&gt;generated-persistence-filter&lt;/description&gt;
      &lt;filter-name&gt;hcpFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;
              org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
          &lt;/filter-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;entityManagerFactoryBeanName&lt;/param-name&gt;
        &lt;param-value&gt;hcp&lt;/param-value&gt;
      &lt;/init-param&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;hcpFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;server&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;com.sun.faces.expressionFactory&lt;/param-name&gt;
      &lt;param-value&gt;com.sun.el.ExpressionFactoryImpl&lt;/param-value&gt;
    &lt;/context-param&gt;
   &lt;context-param&gt;
                  &lt;param-name&gt;primefaces.THEME&lt;/param-name&gt;
                  &lt;param-value&gt;sunny&lt;/param-value&gt;
  &lt;/context-param&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;template.xhtml
              &lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet&gt;
      &lt;description&gt;servlet&lt;/description&gt;
      &lt;servlet-name&gt;HCP Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;classpath:HCP-web-context.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet&gt;
      &lt;description&gt;resources-servlet&lt;/description&gt;
      &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
              org.springframework.js.resource.ResourceServlet
          &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;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/resources/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>