无法使用Apache Camel 3.4.3和Swagger启动Spring Boot 2.3.3。

huangapple go评论85阅读模式
英文:

Unable to start Springboot 2.3.3 with apache camel 3.4.3 and Swagger

问题

我正在尝试从Camel 2.x迁移到3.x。
目标是创建一个带有Swagger文档的API。我可以运行应用程序,但是一旦我添加了Swagger配置,就会出现以下错误:

2020-08-24 16:04:27.174  INFO 21736 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-08-24 16:04:27.176  INFO 21736 --- [  restartedMain] o.a.c.c.s.CamelHttpTransportServlet      : Destroyed CamelHttpTransportServlet[CamelServlet]
2020-08-24 16:04:27.195  INFO 21736 --- [  restartedMain] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-08-24 16:04:27.211 ERROR 21736 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.apache.camel.FailedToStartRouteException: Failed to start route doc-api because of null
        at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:125) ~[camel-base-3.4.3.jar:3.4.3]
        ...
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Cannot find RestApiProcessorFactory in Registry or classpath (such as the camel-openapi-java component)
        at org.apache.camel.component.rest.RestApiEndpoint.createProducer(RestApiEndpoint.java:207) ~[camel-rest-3.4.3.jar:3.4.3]
        ...

我的pom.xml如下:

<!-- 代码略 -->

和我的rest配置如下:

<!-- 代码略 -->

请注意,我已经将原始代码片段中的关键部分进行了翻译,并删除了非必要的细节。如果您有更多需要帮助的问题,请随时提问。

英文:

I'm trying to migrate from camel 2.x to 3.x.
The goal is to create an API with Swagger documentation. I can run the application, but as soon as I add the swagger configuration I get this error:

2020-08-24 16:04:27.174  INFO 21736 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-08-24 16:04:27.176  INFO 21736 --- [  restartedMain] o.a.c.c.s.CamelHttpTransportServlet      : Destroyed CamelHttpTransportServlet[CamelServlet]
2020-08-24 16:04:27.195  INFO 21736 --- [  restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with &#39;debug&#39; enabled.
2020-08-24 16:04:27.211 ERROR 21736 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed
org.apache.camel.FailedToStartRouteException: Failed to start route doc-api because of null
at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:125) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:263) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:156) ~[camel-base-3.4.3.ja
r:3.4.3]
at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:114) ~[camel-base-3.4.3.jar:3
.4.3]
at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2809) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2657) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2620) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.spring.boot.SpringBootCamelContext.doStart(SpringBootCamelContext.java:43) ~[camel-spring-boot-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2452) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:121) ~[camel-spring-3.4.3.jar:3.4.3]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:157) ~[camel-spring-3.4.3.jar:3.4.3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-con
text-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-conte
xt-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-conte
xt-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) ~[spring-context-5.2.8.RELEA
SE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) ~[spring-context-5.2.8.RELEA
SE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898) ~[spring-context-5.2.8.RELE
ASE.jar:5.2.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.8.RELEASE.ja
r:5.2.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring
-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at se.capgemini.kafka.producer.service.KafkaProducerServiceApplication.main(KafkaProducerServiceApplication.java:16) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_252]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_252]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_252]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_252]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.3.RELEASE.jar:2.3.3.RELEASE]
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Cannot find RestApiProcessorFactory in Registry or classpath (such a
s the camel-openapi-java component)
at org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:52) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:67) ~[camel-support-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:84) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:101) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.processor.channel.DefaultChannel.doStart(DefaultChannel.java:143) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:84) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:87) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.processor.Pipeline.doStart(Pipeline.java:154) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:84) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78) ~[camel-support-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:84) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.RouteService.startChildService(RouteService.java:334) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.RouteService.doWarmUp(RouteService.java:184) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:123) ~[camel-base-3.4.3.jar:3.4.3]
... 31 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot find RestApiProcessorFactory in Registry or classpath (such as the camel-openapi-java component)
at org.apache.camel.component.rest.RestApiEndpoint.createProducer(RestApiEndpoint.java:207) ~[camel-rest-3.4.3.jar:3.4.3]
at org.apache.camel.support.DefaultEndpoint.createAsyncProducer(DefaultEndpoint.java:200) ~[camel-support-3.4.3.jar:3.4.3]
at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:232) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:84) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:101) ~[camel-api-3.4.3.jar:3.4.3]
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1459) ~[camel-base-3.4.3.jar:3.4.3]
at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:60) ~[camel-support-3.4.3.jar:3.4.3]
... 46 common frames omitted

My pom.xml looks like this:^

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;groupId&gt;se.capgemini&lt;/groupId&gt;
&lt;artifactId&gt;kafka-producer-service&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;kafka-producer-service&lt;/name&gt;
&lt;description&gt;Demo Spring Boot with Camel and Kafka Producer&lt;/description&gt;
&lt;packaging&gt;war&lt;/packaging&gt;
&lt;properties&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;camel.version&gt;3.4.3&lt;/camel.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-http-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-rest-openapi-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-spring-boot-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-servlet-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-jackson-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;
&lt;artifactId&gt;camel-rest-swagger-starter&lt;/artifactId&gt;
&lt;version&gt;${camel.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;
&lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;
&lt;artifactId&gt;spring-kafka-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

and my rest configuration looks like this:

@Component
public class KafkaProducerAPI extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
//.component(&quot;servlet&quot;)
.contextPath(&quot;/kafka-producer-service&quot;)
.port(8080)
.apiContextPath(&quot;/&quot;)
.apiProperty(&quot;api.title&quot;, &quot;Test REST API&quot;)
.apiProperty(&quot;api.version&quot;, &quot;v1&quot;)
.apiContextRouteId(&quot;doc-api&quot;)
.bindingMode(RestBindingMode.json);
rest()
.tag(&quot;Kafka Producer API&quot;)
.consumes(APPLICATION_JSON_VALUE)
.produces(APPLICATION_JSON_VALUE)
//.bindingMode(RestBindingMode.json)
.description(&quot;something&quot;)
.get(&quot;/test&quot;)
//.outType(Status.class)
.route()
.process(exchange -&gt; {
exchange.getIn().setBody(&quot;Hello world!&quot;);
})
.end()
.endRest();
}
}

Probably I'm missing something simple, as I have a prety similar implementation with camel 2.x and it works just fine.

答案1

得分: 4

我最终通过添加以下内容来修复它:

 &lt;dependency&gt;
			&lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
			&lt;artifactId&gt;camel-swagger-java&lt;/artifactId&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
					&lt;artifactId&gt;*&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
	&lt;/dependency&gt;

此外,com.fasterxml.jackson.core 2.11.2引发了问题,所以我不得不降级到2.10.5。

感谢Claus Ibsen的建议。

英文:

I finally fixed it by adding the following:

 &lt;dependency&gt;
&lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
&lt;artifactId&gt;camel-swagger-java&lt;/artifactId&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;

Also the com.fasterxml.jackson.core 2.11.2 was giving problems so I had to downgrade to 2.10.5.

Thank you for the suggestions Claus Ibsen

huangapple
  • 本文由 发表于 2020年8月24日 22:15:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63562832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定