title: Spring Security Authentication using MyBatis
body: <p>I am trying to perform Spring Security Authentication using MyBatis.</p>
  
  <p>My spring-security file looks as follows</p>
  
  <pre><code>        &lt;global-method-security pre-post-annotations="enabled" /&gt;
  
         &lt;beans:bean id="myUserService"                    
                   class="com.service.CustomService" /&gt;
  
              &lt;authentication-manager&gt;
                  &lt;authentication-provider user-service-ref="myUserService" /&gt;
              &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>My CustomService class <code>implements UserDetailsService</code> and in the <code>loadUserByUsername</code> method , I am using my MyBatis Dao to load the Users from the DB.</p>
  
  <pre><code>@Autowired
  private MyBatisDao dao;
  </code></pre>
  
  <p>In my Controller class I am using the same annotation , and in that case it returns the proper object.</p>
  
  <p>But when I use the same in the CustomService  class it returns <code>null</code>. </p>
  
  <p>I am unable to understand the reason for it. Am i missing something. Please help</p>
  
  <p>Any example of Spring Authentication using MyBatis would help, I can understand it and then maybe figure out the issue</p>