java.lang.ClassNotFoundException: javax.ws.rs.ext.MessageBodyReader in Apache TomEE when trying to use Jackson instead of Johnzon as JSON provider

二次信任 提交于 2019-12-11 16:04:37

问题


Starting from my original problem, I get that I need to specifically configure Apache TomEE to use Jackson as JSON provider (instead of the default Johnzon).

I imported the following in my pom.xml

    <dependency>
        <!-- I only need this first one because otherwise it's ommited due to a conflict.... -->
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.9</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>2.9.9</version>
    </dependency>

After this, I tried several ways:

Mentioning the provider in the ejb-jar.xml file

<pojo-deployment  class-name="jaxrs-application">
    <properties>
        cxf.jaxrs.providers = com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
    </properties>
</pojo-deployment>

Extending the JacksonJaxbJsonProvider with a custom class and registering it:

 @Provider
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public class TGJSONProvider extends JacksonJaxbJsonProvider {
 }

No matter what I do (or even if I don't add anything, I have the same PROBLEM:

2019-05-31 16:11:35 SEVERE org.apache.openejb.observer.ObserverManager$MethodInvocation invoke error invoking org.apache.tomee.webservices.TomeeJaxRsService@12bfd80d
java.lang.NoClassDefFoundError: javax/ws/rs/ext/MessageBodyReader
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    ...
    ...
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.ext.MessageBodyReader
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 55 more

What am I missing / doing wrong ?

Thanks.

来源:https://stackoverflow.com/questions/56396866/java-lang-classnotfoundexception-javax-ws-rs-ext-messagebodyreader-in-apache-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!