将@LoadBalanced与OAuth2RestTemplate一起使用会导致找不到类ClassToken

时间:2015-08-20 07:11:11

标签: spring spring-cloud netflix-eureka

所以,我使用简单的RestTemplate与直接ip:端口到我的服务:

restTemplate.exchange("http://localhost:8081/user", HttpMethod.GET, null, String.class, new HashMap<String, String>());

但现在我想让它知道尤里卡。所以,我已将@LoadBalanced添加到我的restTemplate之上。 Ofcourse myapp这里是在尤里卡注册的服务名称。

@Autowired
@LoadBalanced
public OAuth2RestTemplate restTemplate;

...
restTemplate.exchange("http://myapp/user", HttpMethod.GET, null, String.class, new HashMap<String, String>());
...

但这打破了:

ava.lang.ClassNotFoundException: com.google.common.reflect.TypeToken
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.netflix.client.config.CommonClientConfigKey.<init>(CommonClientConfigKey.java:251)
at com.netflix.client.config.CommonClientConfigKey$1.<init>(CommonClientConfigKey.java:33)
at com.netflix.client.config.CommonClientConfigKey.<clinit>(CommonClientConfigKey.java:33)
at org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration.preprocess(EurekaRibbonClientConfiguration.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)

我是否必须在:

旁边添加任何额外的依赖项
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-security</artifactId>
  <version>1.0.1.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-eureka</artifactId>
  <version>${spring.cloud.version}</version>
</dependency>

0 个答案:

没有答案