REST应用程序在Eclipse中运行,但不是作为可执行jar。 NoClassDefFoundError:javax / xml / bind / annotation / XmlElement

时间:2017-11-28 14:12:18

标签: java rest spring-boot jersey

我使用Jersey注释编写了REST资源。为了在Spring Boot中完成这项工作,我添加了一个JerseyConfiguration类:

12:45:15.311 [main] ERROR o.s.boot.SpringApplication : Application startup failed org.springframework.context.ApplicationContextException: Unable to start embedded container;
nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Bean instantiation via constructor failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$$EnhancerBySpringCGLIB$$d46b8aee]: Constructor threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceConfigCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoCon   figuration$JacksonResourceConfigCustomizer.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer]: Factory method 'resourceConfigCustomizer' threw exception;
nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement

在Eclipse中运行应用程序时,这很好用。当我创建并运行jar文件时,我收到以下错误:

javax/xml/bind/annotation

有人能告诉我为什么会这样吗?据我所知,rt.jar是Java 8 {{1}}

的一部分

我正在使用Spring Boot 1.5.9.RELEASE,Java 8

1 个答案:

答案 0 :(得分:3)

我以为我使用Java 8 SDK启动了jar,但它确实是Java 9 JRE。因此,使用Java 8 SDK java.exe启动jar时不会出现问题。使用Java 8 SDK启动jar已经解决了这个问题。