title: Spring throws exception for undefined bean
body: <p>I am following <a href="http://www.mkyong.com/spring-security/spring-security-hibernate-xml-example/" rel="noreferrer">this tutorial</a> to use Spring Security. I would like to use Hibernate for database queries. I configured the code but following exception is thrown. </p>
  
  <p>I defined the bean in <code>spring-security.xml</code> and <code>my-servlet.xml</code> but still no result.  </p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myMemberDetailsService' is defined
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:570)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1114)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:279)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
      ... 93 more
  </code></pre>
  
  <p><strong>MemberRepository</strong></p>
  
  <pre><code>public class MemberRepositoryImpl implements MemberRepository {
  
      SessionFactory sessionFactory;
  
      @SuppressWarnings("unchecked")
      @Override
      public Member findByUserName(String username) {
  
          List&lt;Member&gt; members = new ArrayList&lt;Member&gt;();
          members = sessionFactory.getCurrentSession()
                  .createQuery("from Member where username=?")
                  .setParameter(0, username).list();
  
          if (members.size() &gt; 0) {
              return members.get(0);
          } else {
              return null;
          }
      }
  
  }
  </code></pre>
  
  <p><strong>MyMemberDetailsService</strong></p>
  
  <pre><code>public class MyMemberDetailsService implements UserDetailsService {
  
      private MemberRepository memberRep;
  
      @Override
      public UserDetails loadUserByUsername(final String username)
              throws UsernameNotFoundException {
  
          Member member = memberRep.findByUserName(username);
          HashSet&lt;String&gt; roles = new HashSet&lt;String&gt;();
          roles.add("ROLE_MEMBER");
          List&lt;GrantedAuthority&gt; authorities = buildUserAuthority(roles);
  
          return buildUserForAuthentication(member, authorities);
  
      }
  
      // Converts com.mkyong.users.model.User user to
      // org.springframework.security.core.userdetails.User
      private User buildUserForAuthentication(Member member,
              List&lt;GrantedAuthority&gt; authorities) {
          return new User(member.getUsername(), member.getPassword(),
                  member.isEnabled(), true, true, true, authorities);
      }
  
      private List&lt;GrantedAuthority&gt; buildUserAuthority(Set&lt;String&gt; userRoles) {
  
          Set&lt;GrantedAuthority&gt; setAuths = new HashSet&lt;GrantedAuthority&gt;();
  
          // Build user's authorities
          for (String userRole : userRoles) {
              setAuths.add(new SimpleGrantedAuthority(userRole));
          }
  
          List&lt;GrantedAuthority&gt; Result = new ArrayList&lt;GrantedAuthority&gt;(
                  setAuths);
  
          return Result;
      }
  
  }
  </code></pre>
  
  <p><strong>my-servlet.xml</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      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/mvc"&gt;
  
  
      &lt;context:annotation-config /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;mvc:view-controller path="/index" /&gt;
      &lt;mvc:view-controller path="/" view-name="index" /&gt;
      &lt;mvc:view-controller path="/signin" /&gt;
  
  
  
      &lt;mvc:resources mapping="resources/**" location="resources/" /&gt;
      &lt;context:component-scan base-package="com.myProject" /&gt;
      &lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate" /&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" /&gt;
      &lt;bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles3.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;/bean&gt;
  
  
      &lt;bean id="memberRep" class="com.myProject.repository.MemberRepositoryImpl"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="myMemberDetailsService" class="com.myProject.service.MyMemberDetailsService"&gt;
          &lt;property name="memberRep" ref="memberRep" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Hibernate Config --&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:8889/myProject" /&gt;
          &lt;property name="username" value="jack" /&gt;
          &lt;property name="password" value="jack" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
          depends-on="dataSource"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan" value="com.myProject.model" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;
          &lt;tx:attributes&gt;
              &lt;tx:method name="get*" read-only="true" /&gt;
              &lt;tx:method name="find*" read-only="true" /&gt;
              &lt;tx:method name="*" /&gt;
          &lt;/tx:attributes&gt;
      &lt;/tx:advice&gt;
  
      &lt;aop:config&gt;
          &lt;aop:pointcut id="userServicePointCut"
              expression="execution(* com.myProject.service.*Service.*(..))" /&gt;
          &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="userServicePointCut" /&gt;
      &lt;/aop:config&gt;
  
      &lt;!-- End Hibernate Config --&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>spring-security.xml</strong></p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="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-3.0.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
  
  
  
      &lt;beans:import resource='login-service.xml' /&gt; 
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/" access="permitAll" /&gt;
          &lt;intercept-url pattern="/member**" access="hasRole('ROLE_MEMBER')" /&gt;
          &lt;intercept-url pattern="/signin" access="permitAll" /&gt;
  
  
          &lt;access-denied-handler error-page="/403" /&gt;
          &lt;form-login login-page="/signin" default-target-url="/index"
              authentication-failure-url="/signin?error" username-parameter="username"
              password-parameter="password" /&gt;
          &lt;logout logout-success-url="/login?logout" /&gt;
          &lt;!-- enable csrf protection --&gt;
          &lt;csrf /&gt;
      &lt;/http&gt;
      &lt;authentication-manager&gt;
          &lt;authentication-provider user-service-ref="myMemberDetailsService"&gt;
              &lt;password-encoder hash="bcrypt" /&gt;
  
  
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  &lt;/beans:beans&gt;
  </code></pre>