![](/img/trans.png)
[英]Spring integration Unzip transformer throws ReplyRequiredException exception
[英]Unzip with spring integration
我想聽一個目錄,讀入新的.zip文件,最好將其傳遞給@ServiceActivator,然后將其解壓縮到目錄中。 在最壞的情況下,我至少要從讀取的zip文件中獲取絕對路徑,並在該路徑上調用java unzip util以將其解壓縮。
這是我的InboundChannelAdapter:
@Bean
@InboundChannelAdapter(value = "requestChannel", poller = @Poller(fixedDelay = "100"))
public FileReadingMessageSource adapter() {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File("path/to/zip/directory"));
return source;
}
這將讀取新的.zip並將其傳遞。 我已經嘗試過一個小型作家,將他們寫入另一個目錄,可以正常工作。
@Bean
@ServiceActivator(inputChannel = "requestChannel" )
public boolean unzipMe() {
byte[] buffer = new byte[1024];
try {
ZipInputStream zis = new ZipInputStream(new FileInputStream("path/to/zip"));
ZipEntry ze = zis.getNextEntry();
while(ze!=null){
String fileName = ze.getName();
File outPut = new File("path/out/directory" + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(outPut);
int len;
System.out.println("output " + outPut.toString());
while((len = zis.read(buffer))> 0){
fos.write(buffer, 0, len);
}
fos.close();
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
這是我的解壓縮方法,它應該被來自requestChannel的消息調用,並解壓縮文件。 目前,我對.zip的路徑進行了硬編碼,因為我無法到達此處的消息。 同樣,這種實現方式給了我這個錯誤,我不明白。
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'integrationConfiguration' defined in file [D:\Workspaces\Integrationnnn\target\classes\demo\IntegrationConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Boolean] for method match: [public static boolean java.lang.Boolean.parseBoolean(java.lang.String), public static java.lang.Boolean java.lang.Boolean.valueOf(boolean), public boolean java.lang.Boolean.booleanValue()]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at demo.IntegrationnnnApplication.main(IntegrationnnnApplication.java:12)
Caused by: java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Boolean] for method match: [public static boolean java.lang.Boolean.parseBoolean(java.lang.String), public static java.lang.Boolean java.lang.Boolean.valueOf(boolean), public boolean java.lang.Boolean.booleanValue()]
at org.springframework.util.Assert.isNull(Assert.java:89)
at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:446)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:192)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:136)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:131)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:57)
at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:37)
at org.springframework.integration.config.annotation.ServiceActivatorAnnotationPostProcessor.createHandler(ServiceActivatorAnnotationPostProcessor.java:65)
at org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.postProcess(AbstractMethodAnnotationPostProcessor.java:117)
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor$1.doWith(MessagingAnnotationPostProcessor.java:151)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:496)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:503)
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessAfterInitialization(MessagingAnnotationPostProcessor.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 13 more
但是,這確實可以可靠地將.zip文件解壓縮到正確的目錄中,然后崩潰。
簡單的解決方案是僅實現我自己的MessageHandler並覆蓋其handleMessageInternal方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.