title: Spring Security OAuth2 Authorization Server /oauth/token - 500 No adapter for handler
body: <p>I am trying to implement Spring Security's OAuth2 Authorization Server. When attempting to access the token endpoint (/oauth/token) I get a 404. I assume there is something I am missing, but for the life of me, I can't see it.</p>
  
  <p>I am using Java configuration for;</p>
  
  <ul>
  <li>Spring Security 4.0.1</li>
  <li>Spring Security OAuth2 2.0.7</li>
  </ul>
  
  <p>My configuration is as follows:</p>
  
  <p>ApplicationSecurityConfig.java</p>
  
  <p>Used to register the configuration files in the WAR</p>
  
  <pre><code>public class ApplicationSecurityConfig extends 
      AbstractSecurityWebApplicationInitializer {
  
      public ApplicationSecurityConfig() {
          super(SecurityConfig.class, AuthorizationServerConfig.class);
      }
  }
  </code></pre>
  
  <p>SpringSecurityConfig.java</p>
  
  <p>Configuring httpbasic authentication for all endpoints matching the URL pattern /</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .inMemoryAuthentication()
              .withUser("user")
              .password("password")
              .roles("USER");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http
              .authorizeRequests()
              .antMatchers("/")
              .authenticated()
          .and()
              .httpBasic();
      }
  }
  </code></pre>
  
  <p>OauthAuthorizationServerConfig.java</p>
  
  <p>Used to configure the authorization server</p>
  
  <pre><code>@Configuration
  @EnableAuthorizationServer
  public class OauthAuthorizationServerConfig extends 
      AuthorizationServerConfigurerAdapter{
  
      @Autowired
      private TokenStore tokenStore;  
  
      @Override
      public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
  
          clients
              .inMemory()
              .withClient("testClient")
              .scopes("read", "write")
              .authorities("ROLE_CLIENT")
              .authorizedGrantTypes("password", "refresh_token")
              .accessTokenValiditySeconds(60)
              .refreshTokenValiditySeconds(3600); 
      }
  
      @Bean
      public TokenStore tokenStore(){
          return new InMemoryTokenStore();
      }
  
      @Override
      public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception{
          endpoints.tokenStore(tokenStore);
      }
  
      @Override
      public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception{
          oauthServer.allowFormAuthenticationForClients();
      }
  
   }
  </code></pre>
  
  <p>Apologies if this is a 'school boy error' but I have spent some time looking at the Documentation and the Samples that Spring have posted on Github, but I'm obviously misunderstanding something. </p>
  
  <p><strong><em>--EDIT--</em></strong></p>
  
  <p>I have replaced 
  ApplicationSecurityConfig.java with SpringApplicationInit.java</p>
  
  <pre><code>public class SpringApplicationInit extends 
      AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
  
          return null;
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[]{
              SpringSecurityConfig.class,
              OauthAuthorizationServerConfig.class
          };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[]{"/"};
      }
  
  }
  </code></pre>
  
  <p>This yeilds different results. I now get a 500 Server error status code:</p>
  
  <pre><code>javax.servlet.ServletException: No adapter for handler [public org.springframework.http.ResponseEntity&lt;org.springframework.security.oauth2.common.OAuth2AccessToken&gt; org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.getAccessToken(java.security.Principal,java.util.Map&lt;java.lang.String, java.lang.String&gt;) throws org.springframework.web.HttpRequestMethodNotSupportedException]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
      org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatchrServlet.java:1163)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
  </code></pre>
  
  <p>I have pushed the code to a git repo if it makes it easier to follow.</p>