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

标签 java rest spring-boot jersey

我已经使用 Jersey 注释编写了 REST 资源。为了在 Spring Boot 中实现这一点,我添加了 JerseyConfiguration 类:

@Configuration
@ApplicationPath("/api")
public class JerseyConfiguration extends ResourceConfig {
    public JerseyConfiguration() {  }

    @PostConstruct
    public void setUp() {
        register(AdminController.class);
        register(AdminResource.class);
        register(GenericExceptionMapper.class);
    }
}

在 Eclipse 中运行应用程序时效果很好。当我创建并运行 jar 文件时,出现以下错误:

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

谁能告诉我为什么会发生这种情况?据我所知,javax/xml/bind/annotation 是 Java 8 rt.jar

的一部分

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

最佳答案

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

关于java - REST 应用程序在 Eclipse 中运行,但不是作为可执行 jar。 NoClassDefFound错误: javax/xml/bind/annotation/XmlElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47533642/

相关文章:

java - 将 byte[] 写入 OutputStream 时添加缓冲区

django - 嵌套路由器与过滤器

spring-boot - 无法使用org.springframework.boot 1.5.19.RELEASE构建gradle项目

java - Spring Boot 中不可解析的父 POM

java - 用 Java 获取完整的 HTML

java - Selenium Webdriver,单击带有类的按钮

java - 处理 HashMap 中的重复值

node.js - 如何授权 HTTP POST 请求以使用 REST API 执行数据流模板

rest - 如何向 Azure 中运行的 docker 容器发送 HTTP 请求

java - 我们何时以及为什么需要 ApplicationRunner 和 Runner 接口(interface)?