gpt4 book ai didi

java - Jersey 上 ResourceConfig 中的依赖关系问题

转载 作者:行者123 更新时间:2023-12-02 03:17:43 26 4
gpt4 key购买 nike

我有一个Jersey/Spring Project A 上的项目 ( com.project.a : Eclipse )这取决于另一个( Project B : com.project.b )。

Eclipse在本地构建并运行应用程序之前,项目上不会显示任何错误Tomcat服务器。

它抛出此错误:

SEVERE: StandardWrapper.Throwable
MultiException stack 1 of 1
java.lang.NoClassDefFoundError: com/project/b/SomeClassToRegister
at com.project.a.CustomApplication.<init>(CustomApplication.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009)
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:905)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:997)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:989)
at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:340)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:319)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:336)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1228)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5449)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5747)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.project.b.SomeClassToRegister
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1955)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1798)
... 28 more

Jul 09, 2019 5:52:13 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [com.project.a.CustomApplication] in web application [/someApplication] threw load() exception
java.lang.ClassNotFoundException: com.project.b.SomeClassToRegister
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1955)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1798)
at com.project.a.CustomApplication.<init>(CustomApplication.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009)
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:905)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:997)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:989)
at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:340)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:319)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:336)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1228)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5449)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5747)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

CustomApplication延伸org.glassfish.jersey.server.ResourceConfig并尝试按如下方式注册该类:

public class CustomApplication extends ResourceConfig {
public CustomApplication() {
// Specify packages of java code.
packages("com.project.a");
packages("com.project.b"); //>>> Line 30
register(com.project.b.SomeClassToRegister.class); //>>> Line 31
}

}

有趣的是,Line 30调用 com.project.b 的主包没有问题,但是代码在 line 31 上崩溃。 com.project.b.SomeClassToRegister存在于依赖项com.project.b .

显示错误后,welcome-file jsp服务器的页面正常显示,但每个端点都会抛出相同的 NoClassDefFoundError访问时出错。

Project A的构建路径有Project B作为列出的依赖项和 Project B也被列为 Web Deployment Assembly 的一部分包装Project A .

我当前正在具有以下资源配置的本地 Tomcat 服务器上运行它。我尝试删除项目 B 的重复外观,结果相同。

enter image description here

我是否遗漏了有关将两个项目链接在一起的任何内容,这可能是导致错误的原因?

最佳答案

在对两个项目的配置进行了大量修改之后,对我有用的是:

  • 转到项目 A 的属性
  • Java 构建路径
  • 来源
  • 添加项目B的文件夹src/main/java
  • 应用并关闭
  • 清理项目并运行

关于java - Jersey 上 ResourceConfig 中的依赖关系问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56950404/

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