java CXF ClassNotFoundException: javax.ws.rs.MessageProcessingException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29054767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:35:58  来源:igfitidea点击:

CXF ClassNotFoundException: javax.ws.rs.MessageProcessingException

javacxfjax-rsjax-ws

提问by Crushing

I'm trying to start a jax ws & rs server endpoints, I can get them started using rs-api 2.0 (and version 2.0.1) but when I try to make a request it throws

我正在尝试启动 jax ws 和 rs 服务器端点,我可以使用 rs-api 2.0(和 2.0.1 版)让它们开始,但是当我尝试发出请求时,它会抛出

java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException  

There are some other threads in SO regarding this matter but the suggestions don't work for me. Using any of the rs-api 2 milestone versions throws issues

SO中还有其他一些关于此事的线索,但这些建议对我不起作用。使用任何 rs-api 2 里程碑版本都会引发问题

Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/BadRequestException

I'm running this as a java application, not a webapp. Anyone have any ideas to try? Thanks

我将它作为一个 java 应用程序运行,而不是一个 web 应用程序。有人有任何想法可以尝试吗?谢谢

EDIT: My dependencies. I added jsr311 but that did not change the MessageProcessingException

编辑:我的依赖项。我添加了 jsr311 但这并没有改变 MessageProcessingException

 <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>

    CXF: version 2.7.0
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
    </dependency>

    rs-api version: 2.0
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
    </dependency>

    jsr311 version: 1.1.1
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
    </dependency>

回答by Ankit Bhatia

Faced the same issue, but later when I used 3.0.0-milestone2of cxf-bundlewith 2.1-m01of javax.ws.rs-api, it worked like a charm.

面对同样的问题,但后来当我用3.0.0-milestone2CXF束2.1-M01javax.ws.rs的API,它的工作就像一个魅力。

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1-m01</version>
</dependency>

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-bundle</artifactId>
    <version>3.0.0-milestone2</version>
</dependency>

回答by k k

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m10</version>
</dependency>

This version has support for javax.ws.rs.MessageProcessingException class.

此版本支持 javax.ws.rs.MessageProcessingException 类。

回答by zooes

I had the same issue & I had to add this exclusion -

我有同样的问题,我不得不添加这个排除 -

            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            </exclusion>

回答by Carlos Lacerda

I took this same error using Jersey client without JSON/JAXB providers to do the calls to server, when I configure Jettison provider the problem was solved. This erros also occour when I use a incompatible POJO to marshaling object to call service. check it. I hope this help.

我在没有 JSON/JAXB 提供程序的情况下使用 Jersey 客户端来调用服务器时出现了同样的错误,当我配置 Jettison 提供程序时,问题就解决了。当我使用不兼容的 POJO 来编组对象以调用服务时,也会出现此错误。核实。我希望这有帮助。

The problem also occur when you have Classloader problems, check your maven dependecy hierarchy conflicts of jax-rs. In my case I need to use exlcusion filter in my pom.xml like

当你有类加载器问题时也会出现这个问题,检查你的 jax-rs 的 maven 依赖层次结构冲突。就我而言,我需要在 pom.xml 中使用排除过滤器,例如

<exclusions>
    <exclusion>
        <artifactId>javax.ws.rs-api</artifactId>
        <groupId>javax.ws.rs</groupId>
    </exclusion>
</exclusions>

I made exclusion in cxf-bundle-jaxrs in another project that uses javax.ws.rs-api dependency. Using dependency of cxf-rt-frontend-jaxrs:2.7.11 was sufficient.

我在另一个使用 javax.ws.rs-api 依赖项的项目中排除了 cxf-bundle-jaxrs。使用 cxf-rt-frontend-jaxrs:2.7.11 的依赖就足够了。