title: How to inject WebResponseExceptionTranslator in TokenEndPoint Spring oAuth2
body: <p>I am trying to customize the way the Spring Security oAuth TokenEndpoint class handles exceptions. I want to return a more customized JSON response than the DefaultWebResponseExceptionTranslator currently does. I cannot figure out how to inject a custom Translator via XML. Here are my code snippets:</p>
  
  <p>spring-security.xml</p>
  
  <pre><code>&lt;oauth:authorization-server
      client-details-service-ref="clientDetails" token-services-ref="tokenServices" 
      user-approval-handler-ref="userApprovalHandler" request-validator-ref="requestValidator" &gt;
      &lt;oauth:client-credentials /&gt;
      &lt;oauth:password /&gt;
  &lt;/oauth:authorization-server&gt;
  </code></pre>
  
  <p>Here is the relevant code portion of AbstractServerBeanDefinitionParser</p>
  
  <pre><code>    BeanDefinitionBuilder tokenEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(TokenEndpoint.class);
      tokenEndpointBean.addPropertyReference("clientDetailsService", clientDetailsRef);
      tokenEndpointBean.addPropertyReference("tokenGranter", tokenGranterRef);
      authorizationEndpointBean.addPropertyReference("oAuth2RequestValidator", oAuth2RequestValidatorRef);
      parserContext.getRegistry()
              .registerBeanDefinition("oauth2TokenEndpoint", tokenEndpointBean.getBeanDefinition());
      if (StringUtils.hasText(oAuth2RequestFactoryRef)) {
          tokenEndpointBean.addPropertyReference("oAuth2RequestFactory", oAuth2RequestFactoryRef);
      }
      if (StringUtils.hasText(oAuth2RequestValidatorRef)) {
          tokenEndpointBean.addPropertyReference("oAuth2RequestValidator", oAuth2RequestValidatorRef);
      }
  </code></pre>
  
  <p>TokenEndpoint extends AbstractEndpoint which is where the translator is defined.</p>
  
  <pre><code>@FrameworkEndpoint
  public class TokenEndpoint extends AbstractEndpoint {
  
      @ExceptionHandler(Exception.class)
      public ResponseEntity&lt;OAuth2Exception&gt; handleException(Exception e) throws Exception {
          logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
          return getExceptionTranslator().translate(e);
      }
  </code></pre>
  
  <p>Here is a snippet from AbtractEndpoint</p>
  
  <pre><code>public class AbstractEndpoint implements InitializingBean {
  
     protected final Log logger = LogFactory.getLog(getClass());
  
     private WebResponseExceptionTranslator providerExceptionHandler = new DefaultWebResponseExceptionTranslator();
  
     public void setProviderExceptionHandler(WebResponseExceptionTranslator providerExceptionHandler) {
         this.providerExceptionHandler = providerExceptionHandler;
     }
  </code></pre>
  
  <p>So my question is. How do I call the setProviderExceptionHandler to pass in my custom class via my spring-security.xml?</p>