1. 程式人生 > >Caused by: java.lang.ClassNotFoundException: feign.Feign$Builder 正確解決方法

Caused by: java.lang.ClassNotFoundException: feign.Feign$Builder 正確解決方法

學習Spring Cloud Feign 的途中發生了一個意外的錯誤:

Caused by: java.lang.ClassNotFoundException: feign.Feign$Builder

在網路上查詢了之後都說是因為pom缺少依賴,只要加入

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

如此的依賴就能恢復正常。
但是!我本來就是添加了依賴那麼該怎麼辦呢。
然後我有查到可能是因為maven下載jar包錯誤,但是我使用maven–test並沒有任何jar包報錯資訊。
在eclipse的後臺輸出的最後一行中,我發現了有一條JVM類載入器的資訊,他會打印出JVM在執行時載入了哪些類。

2018-07-23 15:55:57.090  INFO 9152 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Program%
20Files/Java/jdk1.8.0_151/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/rt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/jfr.jar, file:/C:/Program%
20Files/Java/jdk1.8.0_151/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_151/jre/lib/ext/zipfs.jar, file:/D:/workspace/feign-consumer/target/classes/, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-starter/1.3.7.RELEASE/spring-boot-starter-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot/1.3.7.RELEASE/spring-boot-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-context/4.2.7.RELEASE/spring-context-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-autoconfigure/1.3.7.RELEASE/spring-boot-autoconfigure-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-starter-logging/1.3.7.RELEASE/spring-boot-starter-logging-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar, file:/D:/MavenRes/NewMavenLib/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar, file:/D:/MavenRes/NewMavenLib/org/slf4j/jcl-over-slf4j/1.7.21/jcl-over-slf4j-1.7.21.jar, file:/D:/MavenRes/NewMavenLib/org/slf4j/jul-to-slf4j/1.7.21/jul-to-slf4j-1.7.21.jar, file:/D:/MavenRes/NewMavenLib/org/slf4j/log4j-over-slf4j/1.7.21/log4j-over-slf4j-1.7.21.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-core/4.2.7.RELEASE/spring-core-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/yaml/snakeyaml/1.16/snakeyaml-1.16.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-starter-web/1.3.7.RELEASE/spring-boot-starter-web-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-starter-tomcat/1.3.7.RELEASE/spring-boot-starter-tomcat-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/apache/tomcat/embed/tomcat-embed-core/8.0.36/tomcat-embed-core-8.0.36.jar, file:/D:/MavenRes/NewMavenLib/org/apache/tomcat/embed/tomcat-embed-el/8.0.36/tomcat-embed-el-8.0.36.jar, file:/D:/MavenRes/NewMavenLib/org/apache/tomcat/embed/tomcat-embed-logging-juli/8.0.36/tomcat-embed-logging-juli-8.0.36.jar, file:/D:/MavenRes/NewMavenLib/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.36/tomcat-embed-websocket-8.0.36.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/boot/spring-boot-starter-validation/1.3.7.RELEASE/spring-boot-starter-validation-1.3.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar, file:/D:/MavenRes/NewMavenLib/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, file:/D:/MavenRes/NewMavenLib/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar, file:/D:/MavenRes/NewMavenLib/com/fasterxml/classmate/1.1.0/classmate-1.1.0.jar, file:/D:/MavenRes/NewMavenLib/com/fasterxml/jackson/core/jackson-databind/2.6.7/jackson-databind-2.6.7.jar, file:/D:/MavenRes/NewMavenLib/com/fasterxml/jackson/core/jackson-annotations/2.6.7/jackson-annotations-2.6.7.jar, file:/D:/MavenRes/NewMavenLib/com/fasterxml/jackson/core/jackson-core/2.6.7/jackson-core-2.6.7.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-web/4.2.7.RELEASE/spring-web-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-aop/4.2.7.RELEASE/spring-aop-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-beans/4.2.7.RELEASE/spring-beans-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-webmvc/4.2.7.RELEASE/spring-webmvc-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/spring-expression/4.2.7.RELEASE/spring-expression-4.2.7.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-starter-eureka/1.1.5.RELEASE/spring-cloud-starter-eureka-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-starter/1.1.1.RELEASE/spring-cloud-starter-1.1.1.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-context/1.1.1.RELEASE/spring-cloud-context-1.1.1.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/security/spring-security-rsa/1.0.1.RELEASE/spring-security-rsa-1.0.1.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/bouncycastle/bcpkix-jdk15on/1.47/bcpkix-jdk15on-1.47.jar, file:/D:/MavenRes/NewMavenLib/org/bouncycastle/bcprov-jdk15on/1.47/bcprov-jdk15on-1.47.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-netflix-core/1.1.5.RELEASE/spring-cloud-netflix-core-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-netflix-eureka-client/1.1.5.RELEASE/spring-cloud-netflix-eureka-client-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/eureka/eureka-client/1.4.10/eureka-client-1.4.10.jar, file:/D:/MavenRes/NewMavenLib/org/codehaus/jettison/jettison/1.3.7/jettison-1.3.7.jar, file:/D:/MavenRes/NewMavenLib/stax/stax-api/1.0.1/stax-api-1.0.1.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/netflix-commons/netflix-eventbus/0.3.0/netflix-eventbus-0.3.0.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/archaius/archaius-core/0.7.4/archaius-core-0.7.4.jar, file:/D:/MavenRes/NewMavenLib/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/servo/servo-core/0.10.1/servo-core-0.10.1.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/servo/servo-internal/0.10.1/servo-internal-0.10.1.jar, file:/D:/MavenRes/NewMavenLib/com/sun/jersey/jersey-core/1.19.1/jersey-core-1.19.1.jar, file:/D:/MavenRes/NewMavenLib/com/sun/jersey/jersey-client/1.19.1/jersey-client-1.19.1.jar, file:/D:/MavenRes/NewMavenLib/com/sun/jersey/contribs/jersey-apache-client4/1.19.1/jersey-apache-client4-1.19.1.jar, file:/D:/MavenRes/NewMavenLib/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar, file:/D:/MavenRes/NewMavenLib/org/apache/httpcomponents/httpcore/4.4.5/httpcore-4.4.5.jar, file:/D:/MavenRes/NewMavenLib/commons-codec/commons-codec/1.9/commons-codec-1.9.jar, file:/D:/MavenRes/NewMavenLib/com/google/inject/guice/4.0/guice-4.0.jar, file:/D:/MavenRes/NewMavenLib/javax/inject/javax.inject/1/javax.inject-1.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/governator/governator-api/1.12.10/governator-api-1.12.10.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/eureka/eureka-core/1.4.10/eureka-core-1.4.10.jar, file:/D:/MavenRes/NewMavenLib/com/amazonaws/aws-java-sdk-core/1.11.18/aws-java-sdk-core-1.11.18.jar, file:/D:/MavenRes/NewMavenLib/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.6.6/jackson-dataformat-cbor-2.6.6.jar, file:/D:/MavenRes/NewMavenLib/com/amazonaws/aws-java-sdk-ec2/1.11.18/aws-java-sdk-ec2-1.11.18.jar, file:/D:/MavenRes/NewMavenLib/com/amazonaws/aws-java-sdk-autoscaling/1.11.18/aws-java-sdk-autoscaling-1.11.18.jar, file:/D:/MavenRes/NewMavenLib/com/amazonaws/aws-java-sdk-sts/1.11.18/aws-java-sdk-sts-1.11.18.jar, file:/D:/MavenRes/NewMavenLib/com/amazonaws/aws-java-sdk-route53/1.11.18/aws-java-sdk-route53-1.11.18.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/governator/governator/1.12.10/governator-1.12.10.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/governator/governator-core/1.12.10/governator-core-1.12.10.jar, file:/D:/MavenRes/NewMavenLib/org/ow2/asm/asm/5.0.4/asm-5.0.4.jar, file:/D:/MavenRes/NewMavenLib/org/codehaus/woodstox/woodstox-core-asl/4.4.1/woodstox-core-asl-4.4.1.jar, file:/D:/MavenRes/NewMavenLib/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar, file:/D:/MavenRes/NewMavenLib/org/codehaus/woodstox/stax2-api/3.1.4/stax2-api-3.1.4.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-starter-archaius/1.1.5.RELEASE/spring-cloud-starter-archaius-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/commons-configuration/commons-configuration/1.8/commons-configuration-1.8.jar, file:/D:/MavenRes/NewMavenLib/commons-lang/commons-lang/2.6/commons-lang-2.6.jar, file:/D:/MavenRes/NewMavenLib/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, file:/D:/MavenRes/NewMavenLib/com/google/guava/guava/18.0/guava-18.0.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-starter-ribbon/1.1.5.RELEASE/spring-cloud-starter-ribbon-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon/2.2.0/ribbon-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon-transport/2.2.0/ribbon-transport-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/io/reactivex/rxnetty-contexts/0.4.9/rxnetty-contexts-0.4.9.jar, file:/D:/MavenRes/NewMavenLib/io/reactivex/rxnetty-servo/0.4.9/rxnetty-servo-0.4.9.jar, file:/D:/MavenRes/NewMavenLib/io/reactivex/rxnetty/0.4.9/rxnetty-0.4.9.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-codec-http/4.0.27.Final/netty-codec-http-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-codec/4.0.27.Final/netty-codec-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-handler/4.0.27.Final/netty-handler-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-transport-native-epoll/4.0.27.Final/netty-transport-native-epoll-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-common/4.0.27.Final/netty-common-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-buffer/4.0.27.Final/netty-buffer-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/io/netty/netty-transport/4.0.27.Final/netty-transport-4.0.27.Final.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon-core/2.2.0/ribbon-core-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon-httpclient/2.2.0/ribbon-httpclient-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/netflix-commons/netflix-commons-util/0.1.1/netflix-commons-util-0.1.1.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon-loadbalancer/2.2.0/ribbon-loadbalancer-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/netflix-commons/netflix-statistics/0.1.1/netflix-statistics-0.1.1.jar, file:/D:/MavenRes/NewMavenLib/io/reactivex/rxjava/1.1.5/rxjava-1.1.5.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/ribbon/ribbon-eureka/2.2.0/ribbon-eureka-2.2.0.jar, file:/D:/MavenRes/NewMavenLib/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar, file:/D:/MavenRes/NewMavenLib/com/thoughtworks/xstream/xstream/1.4.2/xstream-1.4.2.jar, file:/D:/MavenRes/NewMavenLib/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar, file:/D:/MavenRes/NewMavenLib/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-starter-feign/1.1.5.RELEASE/spring-cloud-starter-feign-1.1.5.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/cloud/spring-cloud-commons/1.1.1.RELEASE/spring-cloud-commons-1.1.1.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/org/springframework/security/spring-security-crypto/4.0.4.RELEASE/spring-security-crypto-4.0.4.RELEASE.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/feign/feign-core/8.16.2/feign-core-8.16.2.jar, file:/D:/MavenRes/NewMavenLib/org/jvnet/animal-sniffer-annotation/1.0/animal-sniffer-annotation-1.0.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/feign/feign-slf4j/8.16.2/feign-slf4j-8.16.2.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/feign/feign-hystrix/8.16.2/feign-hystrix-8.16.2.jar, file:/D:/MavenRes/NewMavenLib/com/netflix/hystrix/hystrix-core/1.5.3/hystrix-core-1.5.3.jar, file:/D:/MavenRes/NewMavenLib/org/hdrhistogram/HdrHistogram/2.1.7/HdrHistogram-2.1.7.jar]

於是我更具類載入器打印出的資訊,一個資料夾一個資料夾,回溯上去,最後發現是在D:\MavenRes\NewMavenLib\com\netflix\feign\feign-core\8.16.2這個資料夾下的jar包發生了問題。最後刪除原先檔案重新下載解決。