我有一个简单的karaf 4.1,jersey 2.22.1和接收Person对象的ECF 3.14.4客户端 . Person对象是没有注释的POJO,只是名字和名字的getter / setter .

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,jersey和jackson的捆绑包

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);

Now here is the question.

如果我执行以下操作,我的客户工作:

  • 如上所述进行ECF的全新安装

  • 卸载软件包50

50 | Active   |  80 | 2.9.2.v20180207-1730    | Jackson-JAXRS-JSON
  • 安装以下内容:
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
  • 然后安装我的客户端, but it still throws exception
bundle:install -s mvn:ca.dsct.test/simple-rest-client
  • 然后重新启动Karaf容器 . Client now works!!

有人可以解释发生了什么以及我应该做什么,以便我不必手动删除Jackson-JAXRS-JSON包,安装注释包,重新安装JAXRS-JSON包并重新启动Karaf容器

任何帮助表示赞赏 .