2014-10-28 74 views
0

我已經實現了在Spring集成示例中找到的DynamicFtpChannelResolver,以便在我的集成應用程序中允許動態FTP位置。Spring集成DynamicFtpChannelResolver - 無法自動裝載服務bean

作爲出站適配器的一部分,我添加了一個建議鏈。 FtpCompleteAdvice需要訪問現有的服務bean,但在運行時,這不會被注入,因爲上下文是動態創建的。

是否有自動裝配工作方式或其他方式來訪問此服務bean?

這裏是XML的摘錄:

<int:channel id="toFtpChannel" /> 
 

 
<bean id="ftpClientFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"> 
 
    <property name="host" value="${host}" /> 
 
    <property name="port" value="${port}" /> 
 
    <property name="user" value="${user}" /> 
 
    <property name="password" value="${password}" /> 
 
</bean> 
 

 
<int-sftp:outbound-channel-adapter id="ftpOutbound" session-factory="ftpClientFactory" channel="toFtpChannel" remote-directory="${remote.directory}" remote-file-separator="/" remote-filename-generator-expression="headers.filename"> 
 
    <int-sftp:request-handler-advice-chain> 
 
    <bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"> 
 
     <property name="retryTemplate" ref="retryTemplate" /> 
 
    </bean> 
 
    <bean class="com.bstonetech.ptms.integration.util.FtpCompleteAdvice"> 
 
     <property name="interfaceType" value="OUTBOUND" /> 
 
     <property name="interfaceName" value="TEST" /> 
 
    </bean> 
 
    </int-sftp:request-handler-advice-chain> 
 
</int-sftp:outbound-channel-adapter> 
 

 
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate"> 
 
    <property name="retryPolicy"> 
 
    <bean class="org.springframework.retry.policy.SimpleRetryPolicy"> 
 
     <property name="maxAttempts" value="3" /> 
 
    </bean> 
 
    </property> 
 
    <property name="backOffPolicy"> 
 
    <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy"> 
 
     <property name="maxInterval" value="600000" /> 
 
     <property name="initialInterval" value="3000" /> 
 
     <property name="multiplier" value="2" /> 
 
    </bean> 
 
    </property> 
 
</bean>

public class FtpCompleteAdvice extends AbstractRequestHandlerAdvice { 

     @Autowired 
     private IEmailUtilities emailUtilities; 
     @Autowired 
     private IFileService fileService; 

     private String interfaceType; 
     private String interfaceName; 

     public void setInterfaceType(String interfaceType) { 
     this.interfaceType = interfaceType; 
     } 

     public void setInterfaceName(String interfaceName) { 
     this.interfaceName = interfaceName; 
     } 

     @Override 
     protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws   Exception { 

     Object result = callback.execute(); 
     String filename = (String)message.getHeaders().get("filename"); 

     //insert ftp row into file_ctl 

     fileService.insertFtpFile(filename, interfaceName, interfaceType, new Date()); 

     //send email to confirm ftp 

     emailUtilities.afterFtp(filename, interfaceName); 
     return result; 
    } 
} 

回答

0

你需要作出新的背景下,擁有這些豆類的主要背景的孩子。在入站端點使用類似技術時,在示例的自述文件中引用的論壇帖子中對此進行了討論。

然後,父上下文中的任何bean都可用於連線。

+0

謝謝加里。我從帖子中瞭解到,我需要在創建新動態文件時提供父上下文。我如何獲得主要的applicationContext.xml,它將成爲父級?你能指點我一個樣本嗎? – alan 2014-11-08 21:23:43

+0

經過一番研究,我發現我可以實現ApplicationContextAware並可以訪問父應用程序上下文。 – alan 2014-11-08 23:03:25

+0

你也可以'@ Autowire'這個'ApplicationContext'。 – 2014-11-09 14:43:41

相關問題