Java 在apache camel中未找到方案http错误的组件

Java 在apache camel中未找到方案http错误的组件,java,apache-camel,Java,Apache Camel,我已经编写了使用ApacheCamel调用RESTAPI的示例代码。它在单机版中正常工作,但代码与我创建OSGI捆绑包并将其部署到成功创建捆绑包的karaf容器中时使用的代码相同,但我在尝试调用它时遇到了错误,如“没有使用scheme http找到组件” 你能帮我解决这个问题吗? 代码如下: 将以下snipplet添加到您的pom.xml: <dependency> <groupId>org.apache.camel</groupId> &

我已经编写了使用ApacheCamel调用RESTAPI的示例代码。它在单机版中正常工作,但代码与我创建OSGI捆绑包并将其部署到成功创建捆绑包的karaf容器中时使用的代码相同,但我在尝试调用它时遇到了错误,如“没有使用scheme http找到组件”

你能帮我解决这个问题吗?

代码如下:


将以下snipplet添加到您的
pom.xml

<dependency>
     <groupId>org.apache.camel</groupId>
     <artifactId>camel-http</artifactId>
     <version>x.x.x</version>
     <!-- use the same version as your Camel core version -->
 </dependency>

查找有关安装camel for Karaf的更多信息,请查看

如果在OSGi中创建camel上下文,则需要创建OsgiDefaultCamelContext而不是DefaultCamelContext,并且需要将捆绑包上下文作为构造参数传递


如果您使用的是Blueprint或Spring,那么从应用程序上下文中查找camel上下文,然后自己创建一个新的camel上下文,对您来说可能会容易得多。

尝试不仅将条目添加到pom中,而且将HTTPComponent对象添加到camel上下文中,就像这样

    HttpComponent httpComponent = new HttpComponent();
    context.addComponent("http", httpComponent);

初始化bean解决了这个问题。 我的应用程序使用带Spring引导的Camel,DefaultCamelContext的“scheme”值为Null,因为没有设置httpComponent

因此,找不到具有scheme:https的组件

在启动时初始化bean方案按预期设置

导入org.springframework.context.annotation.Bean

@Bean({"http","https"})
HttpComponent httpComponent() {
    return new HttpComponent();
}   

请在pom或build.gradle中添加apache camel http依赖项,这将解决您的错误


例如,实现组:'org.apache.camel',名称:'camel http',版本:'3.1.0'

这将有助于添加错误的整个堆栈跟踪。我对两者使用了相同的版本,但仍然面临相同的问题。@AzhaguvelA您使用OSGI环境吗?我在回答中添加了如何添加
驼峰http
功能。是的,我使用的是OSGI环境。在OSGI列表中,每个camel支持的库都以活动状态安装。我还需要在features console中安装所有这些库吗?如果
camel http
已安装且状态为
Active
(使用
list | grep camel http
),则无需再次安装。camel-http显示在osgi:list下而不是在features:list下。这是正确的安装还是需要在特性组下安装它?考虑指定这个代码片段应该放在什么地方以及是什么导致了这个结论。
features:install camel-http
    HttpComponent httpComponent = new HttpComponent();
    context.addComponent("http", httpComponent);
@Bean({"http","https"})
HttpComponent httpComponent() {
    return new HttpComponent();
}