0%

解决java.lang.ClassNotFoundException: org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory

使用Spring Cloud Feign时遇到如下Class Not Found Error

1
2
3
4
5
6
7
8
9
10
11
12
Caused by: java.lang.NoClassDefFoundError: org/springframework/cloud/client/loadbalancer/LoadBalancedRetryFactory
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_92]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_92]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_92]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_92]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_92]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_92]
... 24 common frames omitted

我使用的软件版本信息如下:

1
2
springCloudVersion = 'Finchley.M2'
springBootVersion = '2.0.0.M3'

解决办法

把openfeign的版本从原来默认的springCloudVersion改为springBootVersion,也就是2.0.0.M3

1
2
// Feign
compile("org.springframework.cloud:spring-cloud-starter-openfeign:${springBootVersion}")