title: Spring-Security PasswordEncoder returns null
body: <p>I have implemented Spring security on my struts2 application and it perfectly works, but it runs into error java.lang.NullPointerException on line 3.</p>
  
  <p>Although it seems passwordEncoder configuration works as by adding those I cant login with a plain text password any more.</p>
  
  <pre><code> &lt;authentication-manager&gt; 
          &lt;authentication-provider&gt;
             &lt;password-encoder ref="passwordEncoder"/&gt;
  
              &lt;jdbc-user-service data-source-ref="dataSource"
  
                             users-by-username-query="
                select username,password,enabled 
                from Users where username=?" 
  
                             authorities-by-username-query="
                        select username,authority 
                        from Users where username = ?"
  
          /&gt;
          &lt;/authentication-provider&gt; 
  
      &lt;/authentication-manager&gt; 
      &lt;beans:bean id="passwordEncoder" 
          xmlns="http://www.springframework.org/schema/beans"            
          class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"&gt;
          &lt;constructor-arg value="256"/&gt;
      &lt;/beans:bean&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p><strong>MyClass.java</strong></p>
  
  <pre><code>    import org.springframework.security.authentication.encoding.ShaPasswordEncoder;;
      ....
      private ShaPasswordEncoder passwordEncoder;
  
       public ShaPasswordEncoder getPasswordEncoder() {
           return passwordEncoder;
       }
       @Autowired
       public void setPasswordEncoder(ShaPasswordEncoder passwordEncoder) {
             this.passwordEncoder = passwordEncoder;
        }
  
       public void encode(String username)
          {
  1             System.err.println("encode password");
  2             String encodedPassword = "";
  3             encodedPassword = passwordEncoder.encodePassword("Jack",username);
  4             System.err.println("encoded password " + encodedPassword);
          }
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>   &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>