Apache Camel似乎不支持在其注册表中使用的任何bean。我目前正在尝试将一个AWS S3 Client对象/ bean添加到spring配置中而没有任何运气。 bean本身被添加到注册表中,但是当camel使用客户端对象时,它会抛出类似于这样的错误:
Caused by: java.lang.IllegalArgumentException: Could not find a
suitable setter for property: amazonS3Client as there isn't a setter method
with same type: java.lang.String nor type conversion possible: No type
converter available to convert from type: java.lang.String to the
required type: com.amazonaws.services.s3.AmazonS3 with value
#amazonClient
amazonClient是前面提到的bean,它适当地添加了spring配置,这让我相信camel配置确实找到了bean。这是相关的xml配置:
<!-- set up default amazon s3 client from amazon aws sdk -->
<bean id="amazonClient" class="com.amazonaws.services.s3.AmazonS3Client">
<constructor-arg>
<bean class="com.amazonaws.auth.BasicAWSCredentials">
<constructor-arg name="accessKey" value=""/>
<constructor-arg name="secretKey" value=""/>
</bean>
</constructor-arg>
</bean>
在camel context部分中(你可以看到提到的bean):
<camel:route id="importFilesFromS3">
<camel:from uri="aws-s3://intuit-commerce-imports?amazonS3Client=#amazonClient&region=us-west-2&deleteAfterRead=true"/>
<camel:to uri="ref:importProcessingEndpoint"/>
</camel:route>
Apache骆驼声称在他们的documentation中有这个功能,但我发现了一些相同的issue来源。链接中的答案没有提供太多解释。
我从未使用过AWS S3,但我也遇到了类似的问题,Camel似乎无法在Spring注册表中找到bean。
通过单步执行IntrospectionSupport.setProperty,我注意到CamelContextHelper.lookup使用的是JndiRegistry而不是ApplicationContextRegistry。
我的解决方案是添加camel-spring作为项目依赖项,以及使用ApplicationContextRegistry初始化我的camel上下文:
camelContext = new DefaultCamelContext(new ApplicationContextRegistry(applicationContext));