【发布时间】:2021-03-11 23:21:29
【问题描述】:
我正在尝试使用 KARAF 构建 camel-rest dsl,但这种招摇似乎行不通。
javax.xml.bind.JAXBException: "org.apache.camel.model.cloud" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:260) ~[jaxb-runtime-2.3.3.jar:2.3.3]
at com.sun.xml.bind.v2.JAXBContextFactory.createContext(JAXBContextFactory.java:48) ~[jaxb-runtime-2.3.3.jar:2.3.3]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:302) ~[?:?]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:478) ~[?:?]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:435) ~[?:?]
at org.apache.camel.xml.jaxb.DefaultModelJAXBContextFactory.newJAXBContext(DefaultModelJAXBContextFactory.java:39) ~[?:?]
at org.apache.camel.xml.jaxb.DefaultModelJAXBContextFactory.newJAXBContext(DefaultModelJAXBContextFactory.java:29) ~[?:?]
at org.apache.camel.xml.jaxb.JaxbModelToXMLDumper.getJAXBContext(JaxbModelToXMLDumper.java:195) ~[?:?]
at org.apache.camel.xml.jaxb.JaxbModelToXMLDumper.dumpModelAsXml(JaxbModelToXMLDumper.java:69) ~[?:?]
at org.apache.camel.swagger.RestSwaggerSupport.getRestDefinitions(RestSwaggerSupport.java:152) ~[!/:3.5.0]
at org.apache.camel.swagger.RestSwaggerSupport.renderResourceListing(RestSwaggerSupport.java:232) ~[!/:3.5.0]
at org.apache.camel.swagger.RestSwaggerProcessor.process(RestSwaggerProcessor.java:120) [!/:3.5.0]
只是正常的休息配置
restConfiguration()
// Use the 'servlet' component.
.component("jetty")
.host("localhost").port(8080)
// Allow Camel to try to marshal/unmarshal between Java objects and JSON
.bindingMode(RestBindingMode.auto)
.dataFormatProperty("prettyPrint", "true")
.dataFormatProperty("mustBeJAXBElement", "false")
.apiContextPath("api-doc")
.apiProperty("api.title", "User API")
.apiProperty("api.version", "1.0.0")
.enableCORS(true);
rest().path("/api")
.consumes("application/json")
.produces("application/json")
.get()
.outType(ResponseType.class)
.description("Get Response").type(ResponseType.class)
.param().name("ab").type(RestParamType.path).description("blah").endParam()
...
pom.xml
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.karaf</groupId>
<artifactId>camel-core-osgi</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java</artifactId>
<version>${camel.version}</version>
</dependency>
<!-- JSON support -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
</dependencies>
作为 rest dsl 服务调用工作正常,但招摇 API 不工作,camel-core-engine 确实有 jaxb.index 文件。我找不到 felix 找不到它的任何原因,或者 felix 没有包含此文件?
【问题讨论】:
-
如何在 OSGi/Karaf 中运行它?好像您自己使用 camel-core-osgi 并以某种方式自己创建骆驼上下文,那么 OSGi 类加载和诸如此类的问题是一个问题,您需要正确/小心如何设置它。否则你会得到 osgi 类加载 hell 就像你在这里一样。
标签: jaxb apache-camel osgi apache-karaf apache-felix