在 Jboss Fuse 6.3 上实现 REST OSGI 服务
implementing a REST OSGI service on Jboss Fuse 6.3
嗨,我正在尝试实现一个简单的 Rest 服务,该服务 returns JSON 对保险丝的响应。以下是我的 POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.fuse.test</groupId>
<artifactId>fuse-hw</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.4.0</version>
<configuration>
<instructions>
<Export-Package></Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
/resources/META-INF/spring下的application.xml是
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<jaxrs:server id="restService" address="http://localhost:9000/lastmile">
<jaxrs:serviceBeans>
<ref bean="lastMileService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jacksonJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
<bean id="lastMileService" class="com.fuse.test.RestService" />
<bean id="jacksonJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
当我在 Fuse 上安装捆绑包时,出现以下错误
**Error executing command: Error starting bundles:
Unable to start bundle 315: Unresolved constraint in bundle org.fuse.test.fuse-hw [315]:
Unable to resolve 315.0: missing requirement [315.0] osgi.wiring.package; (&
(osgi.wiring.package=org.codehaus.jackson.jaxrs)(version>=1.9.0)(!(version>=2.0.0)))**
请协助解决这个问题。
还有 FUSE / Karaf 的任何好的教程/培训视频。网上关于OSGI的资料好像很有限
我明白了,问题是我使用的 jackson 版本与 fuse 6.3 中预建的版本不同。
使用以下命令找出您在 fuse karaf env
中安装的库的版本
JBossFuse:karaf@root> list -l | grep -i "jackson"
[ 146] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/2.6.3
[ 147] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-paranamer/2.6.3
[ 148] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-scala_2.10/2.6.3
[ 300] [Active ] [ ] [ ] [ 50] mvn:org.apache.camel/camel-
jackson/2.17.0.redhat-630187
[ 313] [Active ] [ ] [ ] [ 50]
mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-xml/2.6.3
[ 314] [Active ] [ ] [ ] [ 50] mvn:org.apache.camel/camel-
jacksonxml/2.17.0.redhat-630187
所以我应该使用的版本是 2.6.3,或者更好的选择是使用
<dependency>
<groupId>org.jboss.fuse.bom</groupId>
<artifactId>jboss-fuse-parent</artifactId>
<version>6.3.0.redhat-187</version>
<type>pom</type>
<scope>import</scope>
</dependency>
并且无需指定 jar 的版本。
还有一个与安装任何不属于 fuse bundle 的 jar 有关的问题,请使用以下命令
JBossFuse:karaf@root> install -s wrap:file:/<abc.jar>
嗨,我正在尝试实现一个简单的 Rest 服务,该服务 returns JSON 对保险丝的响应。以下是我的 POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.fuse.test</groupId>
<artifactId>fuse-hw</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.4.0</version>
<configuration>
<instructions>
<Export-Package></Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
/resources/META-INF/spring下的application.xml是
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<jaxrs:server id="restService" address="http://localhost:9000/lastmile">
<jaxrs:serviceBeans>
<ref bean="lastMileService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jacksonJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
<bean id="lastMileService" class="com.fuse.test.RestService" />
<bean id="jacksonJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
当我在 Fuse 上安装捆绑包时,出现以下错误
**Error executing command: Error starting bundles:
Unable to start bundle 315: Unresolved constraint in bundle org.fuse.test.fuse-hw [315]:
Unable to resolve 315.0: missing requirement [315.0] osgi.wiring.package; (&
(osgi.wiring.package=org.codehaus.jackson.jaxrs)(version>=1.9.0)(!(version>=2.0.0)))**
请协助解决这个问题。 还有 FUSE / Karaf 的任何好的教程/培训视频。网上关于OSGI的资料好像很有限
我明白了,问题是我使用的 jackson 版本与 fuse 6.3 中预建的版本不同。 使用以下命令找出您在 fuse karaf env
中安装的库的版本 JBossFuse:karaf@root> list -l | grep -i "jackson"
[ 146] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/2.6.3
[ 147] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-paranamer/2.6.3
[ 148] [Active ] [ ] [ ] [ 80]
mvn:com.fasterxml.jackson.module/jackson-module-scala_2.10/2.6.3
[ 300] [Active ] [ ] [ ] [ 50] mvn:org.apache.camel/camel-
jackson/2.17.0.redhat-630187
[ 313] [Active ] [ ] [ ] [ 50]
mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-xml/2.6.3
[ 314] [Active ] [ ] [ ] [ 50] mvn:org.apache.camel/camel-
jacksonxml/2.17.0.redhat-630187
所以我应该使用的版本是 2.6.3,或者更好的选择是使用
<dependency>
<groupId>org.jboss.fuse.bom</groupId>
<artifactId>jboss-fuse-parent</artifactId>
<version>6.3.0.redhat-187</version>
<type>pom</type>
<scope>import</scope>
</dependency>
并且无需指定 jar 的版本。
还有一个与安装任何不属于 fuse bundle 的 jar 有关的问题,请使用以下命令
JBossFuse:karaf@root> install -s wrap:file:/<abc.jar>