Spring XD(Spring 基于集成 DSL)AWS S3 接收器模块错误
Spring XD (Spring Integration DSL based) AWS S3 sink module error
我正在尝试构建一个 Spring XD(Spring Integration DSL based) sink module using the spring-integration-aws 扩展。我的模块如下所示:
@Configuration
@EnableIntegration
public class S3Module {
@Value("${accessKey:myAccessKey}")
private String accessKey;
@Value("${secretKey:mySecretKey}")
private String secretKey;
@Value("${bucket:myBucket}")
private String bucket;
@Value("${remoteDirectoryExpression:dir}")
private String remoteDirectoryExpression;
@Bean
public AmazonS3MessageHandler handle() {
AWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
AmazonS3MessageHandler handler = new AmazonS3MessageHandler(credentials, new DefaultAmazonS3Operations(credentials));
handler.setBucket(bucket);
handler.setRemoteDirectoryExpression(new LiteralExpression(remoteDirectoryExpression));
return handler;
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from("input")
.handle(handle())
.get();
}
}
我可以成功打包并部署模块。尝试使用以下内容创建流时:
xd:>stream create --name s3test --definition "file --outputType=text/plain --dir='/tmp/logs' | s3" --deploy
我得到以下异常:
00:25:28,850 1.1.0.RC1 INFO DeploymentSupervisor-0 server.StreamDeploymentListener - Deployment status for stream 's3test': DeploymentStatus{state=failed,error(s)=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flow' defined in com.test.xd.S3Module: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'flow' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'flow' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 36 more
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.handle(<generated>)
at com.test.xd.S3Module.flow(S3Module.java:49)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.CGLIB$flow(<generated>)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe$$FastClassBySpringCGLIB$53fd21.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.flow(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 37 more
我很确定我遗漏了一些简单的东西。有人能指出我正确的方向吗?提前致谢!
感谢您做这样的工作!是的,我们一定会在某天向 XD 介绍开箱即用的 AWS 模块。
您的问题与此类似:https://github.com/spring-projects/spring-boot/issues/2441#issuecomment-72758919。
要克服你应该做的事情:
@Bean
public MessageHandler handle() {
将 return 键入为 接口 而不是目标 class。这是因为 Spring 集成 JMX 公开功能在 XD 中默认打开。
题外话:我们很快就要打破SI-AWS,并在Spring Cloud AWS的基础上制作它。我认为 AWSCredentials
内容将被删除,以支持标准 AWS CredentialsProvider
。因此,SI-AWS 1.0.0 将有很多重大变化。
我正在尝试构建一个 Spring XD(Spring Integration DSL based) sink module using the spring-integration-aws 扩展。我的模块如下所示:
@Configuration
@EnableIntegration
public class S3Module {
@Value("${accessKey:myAccessKey}")
private String accessKey;
@Value("${secretKey:mySecretKey}")
private String secretKey;
@Value("${bucket:myBucket}")
private String bucket;
@Value("${remoteDirectoryExpression:dir}")
private String remoteDirectoryExpression;
@Bean
public AmazonS3MessageHandler handle() {
AWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
AmazonS3MessageHandler handler = new AmazonS3MessageHandler(credentials, new DefaultAmazonS3Operations(credentials));
handler.setBucket(bucket);
handler.setRemoteDirectoryExpression(new LiteralExpression(remoteDirectoryExpression));
return handler;
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from("input")
.handle(handle())
.get();
}
}
我可以成功打包并部署模块。尝试使用以下内容创建流时:
xd:>stream create --name s3test --definition "file --outputType=text/plain --dir='/tmp/logs' | s3" --deploy
我得到以下异常:
00:25:28,850 1.1.0.RC1 INFO DeploymentSupervisor-0 server.StreamDeploymentListener - Deployment status for stream 's3test': DeploymentStatus{state=failed,error(s)=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flow' defined in com.test.xd.S3Module: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'flow' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'flow' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 36 more
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy145 cannot be cast to org.springframework.integration.aws.s3.AmazonS3MessageHandler
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.handle(<generated>)
at com.test.xd.S3Module.flow(S3Module.java:49)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.CGLIB$flow(<generated>)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe$$FastClassBySpringCGLIB$53fd21.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at com.test.xd.S3Module$$EnhancerBySpringCGLIB$23ddbe.flow(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 37 more
我很确定我遗漏了一些简单的东西。有人能指出我正确的方向吗?提前致谢!
感谢您做这样的工作!是的,我们一定会在某天向 XD 介绍开箱即用的 AWS 模块。
您的问题与此类似:https://github.com/spring-projects/spring-boot/issues/2441#issuecomment-72758919。
要克服你应该做的事情:
@Bean
public MessageHandler handle() {
将 return 键入为 接口 而不是目标 class。这是因为 Spring 集成 JMX 公开功能在 XD 中默认打开。
题外话:我们很快就要打破SI-AWS,并在Spring Cloud AWS的基础上制作它。我认为 AWSCredentials
内容将被删除,以支持标准 AWS CredentialsProvider
。因此,SI-AWS 1.0.0 将有很多重大变化。