这是我的spring集成xml:我用来学习的一个简单的东西……
<int-file:inbound-channel-adapter id="executionMessageFileInputChannel"
directory="file:${fpml.messages.input}"
prevent-duplicates="false" filename-pattern="*.xml">
<int:poller fixed-delay="20000" max-messages-per-poll="20"/>
</int-file:inbound-channel-adapter>
<int:service-activator input-channel="executionMessageFileInputChannel"
output-channel="executionMessageFileArchiveChannel"
ref="dummyService" method="myMethod"/>
<int-file:outbound-channel-adapter id="executionMessageFileArchiveChannel"
directory="file:${fpml.messages.archive}"
delete-source-files="true" auto-create-directory="true"/>
我真的找不到这方面的好教程..请你指点我
集成java dsl的好教程?
另外,请帮我把它从xml转换为dsl.
更新:( Gary’s Response之后):
我设法把它翻译到这个.
@MessagingGateway
public interface Archive {
@Gateway(requestChannel = "archiveFile.input")
void archive();
}
@Bean
public IntegrationFlow archiveFile() {
return IntegrationFlows
.from(Files.inboundAdapter(new File(dirPath))
.patternFilter("*.xml")
.preventDuplicatesFilter(false),
e -> e.poller(Pollers.fixedDelay(20000)
.maxMessagesPerPoll(20)))
.handle("app","myMethod")
.handle(Files.outboundAdapter(new File(outDirPath)).deleteSourceFiles(true).autoCreateDirectory(true))
.get();
}
只是不确定我是否正确行事.我翻译后立即发布,将测试出来.
测试它:得到以下错误:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘archiveFile’ defined in
si.jdsl.App: Bean instantiation via
factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.springframework.integration.dsl.IntegrationFlow]:
Factory method ‘archiveFile’ threw exception; nested exception is
java.lang.IllegalArgumentException: The ‘filter’
(org.springframework.integration.file.filters.CompositeFileListFilter@48e64352)
is already configured for the FileReadingMessageSource
有什么想法吗?
更新2:
谢谢Gary,这解决了过滤器问题:服务激活器出现问题.以下是我的服务激活者:
@Bean
@ServiceActivator(inputChannel = "archiveFile.input")
public Message<File> myMethod (File inputFile){
Map<String, Object> contextHeader = new HashMap<String, Object>();
return new GenericMessage<File>(inputFile, contextHeader);
}
Initialization of bean failed; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ‘myMethod’ defined in
si.jdsl.App: Unsatisfied dependency
expressed through constructor argument with index 0 of type
[java.io.File]: : No qualifying bean of type [java.io.File] found for
dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations: {}; nested
exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [java.io.File] found for dependency: expected
at least 1 bean which qualifies as autowire candidate for this
dependency. Dependency annotations: {}
请让我知道我错过了什么?
解决方法:
使用Files命名空间工厂.请参阅the DSL reference manual.有一个通用教程here,它逐步转换了咖啡馆样本应用程序的逐行转换. (Java 6/7版本here).
编辑:
这看起来像一个错误,DSL抱怨你正在设置两个过滤器,它不会允许它.
在这种情况下,您实际上不需要这个
.preventDuplicatesFilter(false),
因为这是您提供另一个过滤器时的默认值.
如果您确实需要编写可以使用的过滤器
.filter(myFilter())
其中myFilter是一个带有模式过滤器等的CompositeFileListFilter bean.
编辑2:
@Beans是在初始化时构造的,显然这是一个运行时方法.
使用@ServiceActivator注释@Bean时,它必须是MessageHandler类型.要使用POJO消息传递,您需要一个@MessageEndpoint bean …
@Bean
public MyPojo myPojo() {
return new MyPojo();
}
@MessageEndpoint
public static class MyPojo {
@ServiceActivator(inputChannel = "archiveFile.input")
public Message<File> myMethod (File inputFile){
Map<String, Object> contextHeader = new HashMap<String, Object>();
return new GenericMessage<File>(inputFile, contextHeader);
}
}
您可以在POJO中使用多种消息传递方法.