卡拉夫ECF泽西·杰克逊客户端为JaxbAnnotationIntrospector投掷ClassNotFoundException

时间:2018-12-09 17:57:08

标签: java jackson jersey classnotfoundexception karaf

我有一个简单的karaf 4.1,jersey 2.22.1和ECF 3.14.4客户端,该客户端接收一个Person对象。 Person对象是一个没有注释的POJO,只是名字的获取者/设置者。

private Person getPerson() {
    final String resourceName = "/person";
    log.info("invoking getPerson service");

    ClientConfig config = new ClientConfig();
    Client client = ClientBuilder.newClient(config)
            .register(JacksonFeature.class);
    WebTarget service = client.target( UriBuilder.fromUri(baseURI).build() );

    // invoke GET
    Response response = service
            .path(serviceName)
            .path(resourceName)
            .request(MediaType.APPLICATION_JSON)
            .get();

    if (response.getStatus() != 200) {
        throw new RuntimeException("error status: " + response.getStatus() + " returned from server. Response is: " + response);
    }

    Person person = response.readEntity(Person.class);
    log.info("sucessful response from server: " + person);
    System.out.println("success, received: " + person);
    return person;

我将其部署到干净的Karaf容器中,如下所示:

feature:install scr
feature:repo-add ecf
feature:install ecf-rs-distribution-jersey
bundle:install -s mvn:ca.dsct.test/simple-rest-common   ** this has the person object
bundle:install -s mvn:ca.dsct.test/simple-rest   ** server bundle - tested & working
bundle:install -s mvn:ca.dsct.test/simple-rest-client  ** the client bundle

安装ECF之后,以下是ecf,球衣和杰克逊的捆绑包

karaf@root(bundle)> list -t 0 -n -s | grep ecf
67 | Active   |  80 | 3.9.3.v20181012-2016    | ECF Core API                                                  | org.eclipse.ecf
68 | Active   |  80 | 1.3.0.v20180713-1805    | ECF OSGi Console Command Provider                             | org.eclipse.ecf.console
69 | Active   |  80 | 5.0.300.v20180306-0211  | ECF Discovery API                                             | org.eclipse.ecf.discovery
70 | Active   |  80 | 3.9.1.v20180810-0833    | ECF Identity Core API                                         | org.eclipse.ecf.identity
71 | Active   |  80 | 2.1.200.v20180301-0016  | ECF Remote Service Admin (RSA) Basic Topology Manager         | org.eclipse.ecf.osgi.services.distribution
72 | Active   |  80 | 4.6.800.v20180518-0149  | ECF Remote Service Admin (RSA) Implementation                 | org.eclipse.ecf.osgi.services.remoteserviceadmin
73 | Active   |  80 | 1.2.0.v20180713-1805    | ECF Remote Service Admin (RSA) Console                        | org.eclipse.ecf.osgi.services.remoteserviceadmin.console
74 | Active   |  80 | 1.0.100.v20180301-0016  | ECF Remote Service Admin (RSA) Proxy                          | org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy
75 | Active   |  80 | 1.3.0.201810201256      | ECF Dist Provider - Jax RS Support                            | org.eclipse.ecf.provider.jaxrs
76 | Active   |  80 | 1.3.0.201810201256      | ECF Dist Provider - Jax-RS Client Support                     | org.eclipse.ecf.provider.jaxrs.client
77 | Active   |  80 | 1.5.2.201810201256      | ECF JaxRS Server Support                                      | org.eclipse.ecf.provider.jaxrs.server
78 | Active   |  80 | 1.3.0.201810201256      | ECF Jersey Remote Services Client                             | org.eclipse.ecf.provider.jersey.client
79 | Active   |  80 | 1.4.0.201810201256      | ECF Dist Provider - Jersey Jax RS Server                      | org.eclipse.ecf.provider.jersey.server
80 | Active   |  80 | 8.13.1.v20180801-1752   | ECF RemoteServices API                                        | org.eclipse.ecf.remoteservice
81 | Active   |  80 | 2.1.0.v20180409-2248    | ECF RemoteServices AsyncProxy API Java8                       | org.eclipse.ecf.remoteservice.asyncproxy
82 | Active   |  80 | 2.6.0.v20180404-2345    | ECF SharedObject API                                          | org.eclipse.ecf.sharedobject
karaf@root(bundle)> list -t 0 -n -s | grep jersey
78 | Active   |  80 | 1.3.0.201810201256      | ECF Jersey Remote Services Client                             | org.eclipse.ecf.provider.jersey.client
79 | Active   |  80 | 1.4.0.201810201256      | ECF Dist Provider - Jersey Jax RS Server                      | org.eclipse.ecf.provider.jersey.server
110 | Active   |  80 | 2.22.1.v20161103-1916   | jersey-repackaged-guava                                       | org.glassfish.jersey.bundles.repackaged.jersey-guava
111 | Active   |  80 | 2.22.1.v20161103-0227   | jersey-container-servlet-core                                 | org.glassfish.jersey.containers.servlet.core
112 | Active   |  80 | 2.22.1.v20161103-1916   | jersey-core-client                                            | org.glassfish.jersey.core.jersey-client
113 | Active   |  80 | 2.22.1.v20161103-1916   | jersey-core-common                                            | org.glassfish.jersey.core.jersey-common
114 | Active   |  80 | 2.22.1.v20161103-1916   | jersey-core-server                                            | org.glassfish.jersey.core.jersey-server
115 | Active   |  80 | 2.22.1.v20161103-0227   | jersey-ext-entity-filtering                                   | org.glassfish.jersey.ext.entityfiltering
116 | Active   |  80 | 2.22.1.v20161117-2005   | jersey-media-json-jackson                                     | org.glassfish.jersey.media.jersey-media-json-jackson
karaf@root(bundle)> list -t 0 -n -s | grep jackson
46 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-annotations                                           | com.fasterxml.jackson.core.jackson-annotations
47 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-core                                                  | com.fasterxml.jackson.core.jackson-core
48 | Active   |  80 | 2.9.2.v20180207-1730    | jackson-databind                                              | com.fasterxml.jackson.core.jackson-databind
49 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-JAXRS-base                                            | com.fasterxml.jackson.jaxrs.jackson-jaxrs-base
50 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-JAXRS-JSON                                            | com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider
116 | Active   |  80 | 2.22.1.v20161117-2005   | jersey-media-json-jackson                                     | org.glassfish.jersey.media.jersey-media-json-jackson 

当客户端捆绑包启动时,我得到一个:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector
at com.fasterxml.jackson.jaxrs.json.JsonMapperConfigurator._resolveIntrospector(JsonMapperConfigurator.java:109) ~[?:?]
at com.fasterxml.jackson.jaxrs.json.JsonMapperConfigurator._resolveIntrospectors(JsonMapperConfigurator.java:84) ~[?:?]
...
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider [50]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639) ~[?:?]

我的客户端尝试反序列化Person对象时发生异常:

Person person = response.readEntity(Person.class);

现在是问题。

如果我执行以下操作,则我的客户端可以正常工作:

  1. 按上述全新安装ECF
  2. 卸载捆绑软件50

    50 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-JAXRS-JSON
    
  3. 安装以下内容:

    bundle:install -s mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/2.9.2
    bundle:install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/2.9.2
    
  4. 然后安装我的客户端,但仍然会引发异常

    bundle:install -s mvn:ca.dsct.test/simple-rest-client
    
  5. 然后重新启动Karaf容器。 客户端现在可以正常工作!

有人可以解释正在发生的事情以及我应该怎么做,这样我就不必手动删除Jackson-JAXRS-JSON捆绑包,安装注释捆绑包,重新安装JAXRS-JSON捆绑包并重新启动牛皮纸容器

感谢您的帮助。

0 个答案:

没有答案