title: Annotations on Spring while using Shiro , NullPointerException
body: <pre><code>@DependsOn(value="userService")
  public class AuthcRealm implements Realm {
  
  @Autowired
  @Lazy(value=false)
  @Qualifier(value="userService")
  private UserServiceImpl userService;//here I did the injection
  
  public AuthcRealm() {
      System.out.print("realm constructor");
  }
  
  public String getName() {
      return "AuthenticateRealm";
  }
  
  public boolean supports(AuthenticationToken token) {
      return token instanceof UsernamePasswordToken;
  }
  
  public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
      //serServiceImpl userService=new UserServiceImpl();
      User user=new User();
      user.setUsername((String)token.getPrincipal());
      user.setCredential(new String((char[])token.getCredentials()));
      System.out.println((String)token.getPrincipal());
      System.out.println(new String((char[])token.getCredentials()));
      System.out.println(userService.getClass().toString());//at here I got a NullPointerException
  
      if(!userService.isExist(user)){
          System.out.println("user not exist");
          throw new UnknownAccountException();
      }
  
      if(!userService.isValid(user)){
          throw new IncorrectCredentialsException();
      }
  
      return new SimpleAuthenticationInfo(user.getUsername(), user.getCredential(), getName()); 
  
      }
  }
  </code></pre>
  
  <p>tomcat gives me error output below:</p>
  
  <pre><code>    Serious: Servlet.service() for servlet [spring] in context with path [/Fentalk] threw exception [Request processing failed; nested exception is org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - ADMIN, rememberMe=false].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).] with root cause
  java.lang.NullPointerException
      at com.fentalk.shiro.realm.AuthcRealm.getAuthenticationInfo(AuthcRealm.java:46)
      at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
      at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
      at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
      at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
      at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
      at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
      at com.fentalk.ctrl.AccountController.doLogin(AccountController.java:58)
  </code></pre>
  
  <p>Mostly telling me my userService failed to inject , getting a <code>NullPointerException</code></p>
  
  <p>The token is firstly build in my <code>AccountController</code>.</p>
  
  <p>I already made sure spring is scanning this class , and the token is not null.</p>
  
  <p>Some good fellas ask for shiro configuration, here it is</p>
  
  <pre><code>&lt;bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"&gt;
      &lt;property name="realm" ref="authRealm" /&gt; 
  &lt;/bean&gt;
  &lt;bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"&gt;  
      &lt;property name="securityManager" ref="securityManager" /&gt;  
      &lt;property name="loginUrl" value="/home/index.jsp" /&gt;  
      &lt;property name="successUrl" value="/main/index" /&gt;  
      &lt;property name="filterChainDefinitions"&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id=" authRealm" class="com.fentalk.shiro.realm.AuthcRealm"&gt;   
  &lt;/bean&gt;
  
  
  &lt;bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/&gt;
  </code></pre>