2016-09-07 72 views
0

我們使用微服務和oauth2作爲安全機制。 目前,我們正在呼籲其他微服務與OAuth2RestTemplate這樣的:春季雲偵察和Oauth2模板

template.postForObject("http://"+MY_DISCOVERY_NAME+"/path/to/restservice", params, Void.class); 

我們正在使用@Autowired注入OAuth2RestTemplate如下:

@Configuration 
    public class ApplicationConfig { 

     @Autowired 
     OAuth2RestTemplate oauth2Resttemplate; 
     ... 
     @Bean 
     public MyBean getMyBean() { 
      MyBeanImpl myBean = new MyBeanImpl(); 
      oauth2Resttemplate.setErrorHandler(getErrorHandler()); 
      myBean.setTemplate(oauth2Resttemplate); 
      return myBean; 
     } 
     ... 
    } 

我們那麼下一步就是打的電話tracable 。 我們想用春天的雲偵察。

所以我加了依賴如下:

<dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-starter-sleuth</artifactId> 
    </dependency> 

之後,春天是不能再自動裝配OAuth2RestTemplate:

Caused by: java.lang.IllegalArgumentException: Can not set org.springframework.security.oauth2.client.OAuth2RestTemplate 

在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor的拋出IllegalArgumentException:

  @Override 
      protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { 
       ... 

          } 
          if (value != null) { 
            ReflectionUtils.makeAccessible(field); 
            field.set(bean, value); 
          } 
        } 
       ... 

field.set(bean, value);導致以下情況除外:

java.lang.IllegalArgumentException: Can not set org.springframework.security.oauth2.client.OAuth2RestTemplate field my.package.ApplicationConfig.oauth2Resttemplate to com.sun.proxy.$Proxy120 

我如何結合使用OAuth2RestTemplate與偵探?

感謝

最大

+0

這很有趣...你可以在某個地方發佈樣本嗎?你也可以發佈更多的堆棧跟蹤? –

回答

0

的問題是,我有線OAuth2RestTemplate而不是接口OAuth2RestOperations的。

連線OAuth2RestOperations適用於我。