gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:51:02 25 4
gpt4 key购买 nike

我使用 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。 NoClassDefFoundError : javax/xml/bind/annotation/XmlElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47533642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com