在Tomcat实例中找不到该类,即使每一个可能包含该类的构件都被作为依赖关系包含在内。

问题描述 投票:1回答:1
SEVERE: Servlet [com.mycompany.mycms.screport.services.CmsPortfolioConfig] in web application [] threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
    at org.apache.catalina.core.DefaultInstanceManager$PrivilegedLoadClass.run(DefaultInstanceManager.java:835)
    at org.apache.catalina.core.DefaultInstanceManager$PrivilegedLoadClass.run(DefaultInstanceManager.java:823)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1031)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4854)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:928)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:638)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

我有一个Tomcat应用程序,主要通过Jersey的JAX-RS实现提供RESTful api服务。 在启动时的某一时刻,它决定抛出上面的类未找到异常。起初,我从这些依赖关系入手。

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.server.version}</version>
        </dependency>

但它并不在意,并给了我同样的堆栈跟踪。于是我放弃了,在绝望中尝试了所有剩下的依赖。

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.server.version}</version>
        </dependency>

我进行了构建,并要求Eclipse将更改发布到Tomcat实例(v9)中。但我得到了上面的堆栈跟踪。 我试着添加这个依赖关系,因为search.maven.org报告说它提供了缺少的类。

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.server.version}</version>
        </dependency>
        <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.31</version>
</dependency>
    <dependency>
        <groupId>org.glassfish.jersey.bundles</groupId>
        <artifactId>jaxrs-ri</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.connectors</groupId>
        <artifactId>jersey-helidon-connector</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-wadl-doclet</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-jaxb</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.test-framework.maven</groupId>
        <artifactId>custom-enforcer-rules</artifactId>
        <version>2.31</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.examples</groupId>
        <artifactId>xml-moxy</artifactId>
        <version>2.31</version>
    </dependency>


    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.server.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <version>${jersey.server.version}</version>
    </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${jersey.server.version}</version>
        </dependency>

而它 没有在意。 I 思想 它在抱怨,因为它找不到类。 如果我没有提供这个类,我可以理解。 然而,我以为maven搜索工具中的fc:限定词可以让我找到提供该类的工件。 不知为何,这一切都不正确。

另外,我可以按Ctrl-Shift-T键,输入完全限定的类型,在Eclipse中就能看到它,甚至连源码都能看到。 我不知道为什么它找不到那个类。

另外,我的服务都从Tomcat返回404。 不知道是因为这个错误还是其他原因。

亲切的感谢,WMhttps:/search.maven.orgsearch?q=fc:org.glassfish.jersey.servlet.ServletContainer%20v:2.31。

java maven tomcat jersey
1个回答
0
投票

我建议,请检查项目中的部署汇编。你可以在eclipse中通过右键点击项目并进入属性来进行检查。所有的东西都部署在那里了吗?也许你在源文件中拥有所有的类,但它还没有被部署。

© www.soinside.com 2019 - 2024. All rights reserved.