【问题标题】:jersey servlet exception tomcatjersey servlet 异常 tomcat
【发布时间】:2011-11-19 00:56:01
【问题描述】:

试图启动一个简单的 Jersey - Spring webapp,我快疯了。我在尝试访问网络资源时从 Tomcat 得到的错误是:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet Jersey Spring Web Application threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:619)

root cause

com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
    com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69)
    com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:391)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.create(ServletContainer.java:306)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:607)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    javax.servlet.GenericServlet.init(GenericServlet.java:212)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:619)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.28 logs.

我的web.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:application-context.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>

        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.companyname.abc</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <url-pattern>/webresources/*</url-pattern>
    </servlet-mapping>
</web-app>

任何想法我做错了什么?

【问题讨论】:

    标签: tomcat servlets jersey


    【解决方案1】:

    我遇到了同样的问题,经过一些调查和 amak 的提示,它与 hbase 依赖关系有关,很明显问题是由于我在项目中使用 jersey 1.10 时 HBase 导入 jersey 1.4 引起的。排除 HBase 引入的球衣工件后,一切似乎都很好:

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase</artifactId>
            <version>0.90.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>jersey-core</artifactId>
                    <groupId>com.sun.jersey</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jersey-json</artifactId>
                    <groupId>com.sun.jersey</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jersey-server</artifactId>
                    <groupId>com.sun.jersey</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    

    希望有帮助..

    【讨论】:

    • 使用 Swagger 时出现类似问题。谢谢!
    • @TomTasche +1 给你。我在谷歌搜索“swagger with jersey and springservlet”时发现了这个问题,结果这也是我的问题。
    • +1 给你@TomTasche,这肯定拯救了我的一些脑细胞
    【解决方案2】:

    如果您只是想让一个基本示例正常工作,那不应该发生。也许你有一个损坏的 jersey-server jar。尝试删除现有的并下载一个新的。

    此错误意味着您的 jar 缺少文件 META-INF/services/com.sun.jersey.spi.container.WebApplicationProvider,该文件告诉它使用哪个 WebApplicationProvider。

    【讨论】:

    • 很奇怪,我发现它是我的 pom 文件 org.apache.hbasehbase0.90 的以下条目。 3-cdh3u1
    • 对我来说也一样。删除 hbase 0.90.4 依赖解决了问题
    【解决方案3】:

    就我而言

    mvn dependency:tree

    向我表明使用了另一个版本的 jersey-server。我包含了 1.12 版,但在树中出现了

    com.sun.jersey:jersey-server:jar:1.9-ea07:compile

    修复这个奇怪的依赖后,错误消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2018-06-29
      • 2017-12-20
      • 2018-09-20
      相关资源
      最近更新 更多