2016-03-30 32 views
0

Yay yayı güvenliği oAuth2 istemcisini kullanıyorum. Ve gerekenlerBahar içeriğinde varsayılan OAuth2RestTemplate'i geçersiz kılma

@Bean 
@Primary 
public OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext, 
     OAuth2ProtectedResourceDetails details) { 
    OAuth2RestTemplate template = new OAuth2RestTemplate(details, 
      oauth2ClientContext); 
    return template; 
} 

özel hata burada

@Bean 
public OAuth2RestTemplate restTemplate(OAuth2ClientContext oauth2ClientContext,  
     OAuth2ProtectedResourceDetails details) { 
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(details, oauth2Context); 

    restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { 
     @Override 
     public void handleError(ClientHttpResponse response) throws IOException { 
      // do some stuff 
     } 
    }); 

    return restTemplate; 
} 

gibi bağlam içine konuyu koymak için çalışıyorum böylece taşıma sağlamaktır benziyor varsayılan OAuth2RestTemplate beyanı var olmasıdır varsayılan uygulama @Primary olarak açıklanmıştır ve bu yüzden nasıl geçersiz kılınabileceğini merak ediyorum?

cevap

0

Varsayılan uygulamayı geçersiz kılmak yerine, muhtemelen varsayılan örneği alabilir ve gereksinim duyduğunuz tüm özellikleri ayarlayabilirsiniz. Aşağıdaki örneğe bakınız.

@Configuration 
public class OverridenConfiguration { 
    @Autowire 
    private OAuth2RestTemplate restTemplate; 

    @PostConstruct 
    public void customSettings() { 
     System.out.println("************** custom settings ***********"); 
     restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { 
      @Override 
      public void handleError(ClientHttpResponse response) throws IOException { 
       // do some stuff 
      } 
     }); 
    } 
} 
İlgili konular