我有一个豆子
@Component
public class SqsClient {
@Autowired
private AWSCredentialsProvider customChain;
@Value("my-region")
private String region;
private AmazonSQS sqsClient;
@PostConstruct
private void init() {
sqsClient = AmazonSQSClientBuilder.standard()
.withRegion(region)
.withCredentials(customChain)
.build();
}
public AmazonSQS getAmazonSQSClient() {
return sqsClient;
}
}
同样在我的上下文中我声明了路径
<route id="process.sqs.message">
<from uri="aws-sqs://{{aws.sqs.queue}}?amazonSQSClient=#sqsClient"/>
<to url="bean:sqsQueueListener?method=processMessage(${body})"/>
</route>
但是当我启动应用程序时,我得到了异常
Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: amazonSQSClient 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.sqs.AmazonSQS with value #sqsClient
为什么它无法设置amazonSQSClient
?
答案 0 :(得分:2)
因为amazonSQSClient
组件上的aws-sqs
参数必须是对Camel注册表中com.amazonaws.services.sqs.AmazonSQS
的引用。
将@Bean
注释添加到您的getter中,其名称与您在aws-sqs
端点中引用它的名称相同:
@Bean(name = "sqsClient")
public AmazonSQS getAmazonSQSClient() {
return sqsClient;
}