springcloud启动eureka报错java.lang.ClassNotFoundException: com.sun.jersey.api.core.DefaultResourceConfig

最近开始学习spring cloud,因为钱不久使用过spring boot,所以轻松上手。

然后弄清楚我们的消费者 服务者 服务发现者,然后就跟着教程走起来,然后就悲剧的出现如下的一幕


换了四五个版本的 cloud.version 同样出现问题:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [cloud.eureka.server.EurekaServer]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:519) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:278) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:168) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at cloud.eureka.server.EurekaServer.main(EurekaServer.java:16) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:510) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/sun/jersey/api/core/DefaultResourceConfig
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_151]
at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_151]
at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_151]
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.api.core.DefaultResourceConfig
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_151]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]

at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]


理论上我还是认为maven搞的好好的,不会出现这样的错误,但是最终还是没办法,找不到类就是找不到类

就直接上网找这个:com.sun.jersey.api.core.DefaultResourceConfig

然后塞进maven里面,也可以先下载jar放进去试试

远程地址如下:

http://grepcode.com/snapshot/repo1.maven.org/maven2/com.sun.jersey/jersey-bundle/1.19/

我使用的jersey 1.19.1 所以我找的1.19 然后就ok 了,大家自己看下自己的jersey版本,自动添加

下面是maven代码:

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
          <version>1.19</version>
      </dependency>

搞定,启动妥妥的,eureka成功启动.


这是今天新加的,使用spring cloud并用maven打包独立运行时出现异常,始终无法处理,没办法最终又回到了
java.lang.ClassNotFoundException: com.sun.jersey.api.core.DefaultResourceConfig
这一次到墙外面逛了一圈,还是老外经验足:
url: https://github.com/spring-projects/spring-boot/issues/1345
pom.xml 添加如下代码
                <plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
   <configuration>
       <requiresUnpack>
               <dependency>
                       <groupId>com.sun.jersey</groupId>
                       <artifactId>jersey-server</artifactId>
               </dependency>
               <dependency>
                       <groupId>com.sun.jersey</groupId>
                       <artifactId>jersey-core</artifactId>
               </dependency>
               <dependency>
                       <groupId>com.sun.jersey</groupId>
                       <artifactId>jersey-servlet</artifactId>
               </dependency>
       </requiresUnpack>
   </configuration>

</plugin>


报错的原因是因为jar出现了冲突:导出的jar也能正常运行,算是把这个坑填好了



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页