Rest service with oauth2: Failed to find access token for token
<p>I try to create spring rest service, whis is autenticated by my own oauth2 resources server. I created resource server:</p>

<pre><code>@Configuration
@EnableResourceServer
protected static class ResourceServer extends ResourceServerConfigurerAdapter {

    @Autowired
    private TokenStore tokenStore;

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.tokenStore(tokenStore).resourceId("mobileapp");
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/api/shop /**").authenticated().and()
                .authorizeRequests().antMatchers("/auth/**").anonymous();
    }

}
</code></pre>

<p>and authorization server:</p>

<pre><code>@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager auth;

    @Autowired
    private DataSource dataSource;

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Bean
    public JdbcTokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }

    @Bean
    protected AuthorizationCodeServices authorizationCodeServices() {
        return new JdbcAuthorizationCodeServices(dataSource);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.passwordEncoder(passwordEncoder);
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints
                .authorizationCodeServices(authorizationCodeServices())
                .authenticationManager(auth)
                .tokenStore(tokenStore())
                .approvalStoreDisabled();
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.jdbc(dataSource)
                .passwordEncoder(passwordEncoder);
                .withClient("mobile")
                .authorizedGrantTypes("password", "refresh_token")
                .authorities("ROLE_CLIENT")
                .scopes("read", "write", "trust")
                .autoApprove(true)
               .resourceIds("mobileapp")
                .secret("123456");
    }
</code></pre>

<p>When I try to receive an access token from server, using curl: </p>

<blockquote>
  <p>curl -X POST -vu mobile:123456 <a href="http://localhost:8080/oauth/token" rel="nofollow">http://localhost:8080/oauth/token</a> -H
  "Accept: application/json" -d
  "password=test123&amp;username=admin@gmail.com&amp;grant_type=password&amp;scope=read&amp;client_secret=123456&amp;client_id=mobile"</p>
</blockquote>

<p>I get this error as a response message:</p>

<blockquote>
  <p>{"error":"server_error","error_description":"java.io.NotSerializableException:
  org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"}</p>
</blockquote>

<p>In tomcat logs there is also </p>

<blockquote>
  <p>o.s.s.o.p.token.store.JdbcTokenStore - Failed to find access token for
  token</p>
</blockquote>

<p>EDIT:
Bean definition of password encoder:</p>

<pre><code>@Bean
public BCryptPasswordEncoder passwordEncoder() {
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    return bCryptPasswordEncoder;
}
</code></pre>

<p>This bean is created in class, in which OAuth2Config and ResourceServer are declared.</p>

<p>I checked code and found out which table spring uses and the table is empty. My question is: should it be auto generated or there is a problem with my code? </p>

<p>Thanks in advance for help.</p>