我正在尝试将码头组件与Apache骆驼一起使用,并仅打印“ Hello World”消息。 但是我遇到一个错误,该错误提示-> 由于以下原因,无法解析端点:jetty:// http://localhost:8888/sample,原因是:未找到使用scheme:jetty的组件, 即使我在pom.xml中添加了对码头的依赖。请告诉我我做错了。下面是我的代码和pom文件
package com.rama.example;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class JettyGreeting {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
from("jetty:http://localhost:8888/sample")
.log("Received a request")
.setBody(simple("Hello, World"));
}
});
while(true)
context.start();
}
}
<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>com.example</groupId>
<artifactId>camel-rest-expose</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-jetty -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[jetty:http://localhost:8888/sample] -> [L... because of Failed to resolve endpoint: jetty://http://localhost:8888/sample due to: No component found with scheme: jetty
at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:118)
at org.apache.camel.impl.DefaultModel.start(DefaultModel.java:356)
at org.apache.camel.impl.DefaultModel.startRoute(DefaultModel.java:330)
at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:323)
at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:302)
at org.apache.camel.impl.AbstractModelCamelContext.startRouteDefinitions(AbstractModelCamelContext.java:326)
at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2679)
at org.apache.camel.impl.engine.AbstractCamelContext.lambda$doStart$2(AbstractCamelContext.java:2527)
at org.apache.camel.impl.engine.AbstractCamelContext.doWithDefinedClassLoader(AbstractCamelContext.java:2544)
at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2525)
at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:121)
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2421)
at com.rama.example.JettyGreeting.main(JettyGreeting.java:26)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jetty://http://localhost:8888/sample due to: No component found with scheme: jetty
at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:834)
at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:57)
at org.apache.camel.impl.engine.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:123)
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:367)
at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:112)
... 12 more
答案 0 :(得分:3)
您的骆驼码头测试属于pom.xml
文件中。删除该码头,使之成为您应用程序的一部分。