我们正在使用Camel REST DSL。我们使用netty4-http组件(通过camel-spring-boot支持)。
相关工作代码/配置如下:
的build.gradle:
dependencies {
compile (group: 'org.apache.camel', name: 'camel-spring-boot', version: '2.16.1')
compile (group: 'org.apache.camel', name: 'camel-netty4-http', version: '2.16.1')
compile (group: 'org.apache.camel', name: 'camel-jackson', version: '2.16.1')
compile (group: 'org.apache.camel', name: 'camel-swagger-java', version: '2.16.1')
compile (group: 'org.apache.camel', name: 'camel-cxf', version: '2.16.1')
compile (group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.1.RELEASE')
我们的路线:
@Component
public class ExampleRestDslRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("netty4-http")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.host("0.0.0.0")
.contextPath(restApiBaseUrl)
.port("10000")
.apiContextPath("/api-doc")
.apiProperty("api.description", restApiDesc)
.apiProperty("api.title", restApiTitle)
.apiProperty("api.version", restApiVersion)
.apiProperty("cors", "true");
rest("/hello").description("Say hello.")
.produces("application/json")
.get().description("Get hello.").route().transform(constant("BOOOOOOOM!!!!!"));
}
然而,我们希望用jetty组件替换netty(Jetty使用Coda Hale指标进行检测)。从文档([1]& [2])看来我们应该做出以下改变:
的build.gradle:
compile (group: 'org.apache.camel', name: 'camel-jetty9', version: '2.16.1')
我们的路线:
restConfiguration()
.component("jetty")
但是当我们这样做时,我们会在启动时看到这个堆栈跟踪:
12:31:53.805 [main] ERROR o.springframework.boot.SpringApplication - Application startup failed
org.apache.camel.spring.boot.CamelSpringBootInitializationException: java.lang.IllegalArgumentException: Component jetty is not a RestApiConsumerFactory
at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:87) ~[camel-spring-boot-2.16.1.jar:2.16.1]
at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:37) ~[camel-spring-boot-2.16.1.jar:2.16.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:855) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.ringApplication.doRun(SpringApplication.java:357) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.apache.camel.spring.boot.FatJarRouter.main(FatJarRouter.java:26) [camel-spring-boot-2.16.1.jar:2.16.1]
Caused by: java.lang.IllegalArgumentException: Component jetty is not a RestApiConsumerFactory
at org.apache.camel.component.rest.RestApiEndpoint.createConsumer(RestApiEndpoint.java:220) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:68) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:98) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:158) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3453) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3383) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3160) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3016) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2812) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2808) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2831) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2808) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.support.Serport.start(ServiceSupport.java:61) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2777) ~[camel-core-2.16.1.jar:2.16.1]
at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:85) ~[camel-spring-boot-2.16.1.jar:2.16.1]
... 13 common frames omitted
[1] https://camel.apache.org/rest-dsl.html [2] https://camel.apache.org/jetty.html
答案 0 :(得分:1)
我们需要升级到骆驼版本2.16.2(感谢@clausibsen - 请参阅上面的评论)。
dependencies {
compile (group: 'org.apache.camel', name: 'camel-spring-boot', version: '2.16.2')
compile (group: 'org.apache.camel', name: 'camel-jetty9', version: '2.16.2')
compile (group: 'org.apache.camel', name: 'camel-jackson', version: '2.16.2')
compile (group: 'org.apache.camel', name: 'camel-swagger-java', version: '2.16.2')
compile (group: 'org.apache.camel', name: 'camel-cxf', version: '2.16.2')
compile (group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.1.RELEASE')