2014-10-28 1 views
0

통합 통합 프로그램에서 동적 FTP 위치를 허용하기 위해 DynamicFtpChannelResolver을 스프링 통합 샘플에서 발견했습니다.스프링 통합 DynamicFtpChannelResolver - 서비스 bean을 autowire 할 수 없음

아웃 바운드 어댑터의 일부로 조언 체인을 추가했습니다. FtpCompleteAdvice은 기존 서비스 빈에 대한 액세스가 필요하지만 런타임에는 컨텍스트가 동적으로 생성되기 때문에 아마도 삽입되지 않습니다.

이 서비스 빈에 액세스하기 위해 자동 와이어링을 작동시키는 방법이나 다른 방법이 있습니까?

<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

당신은 새로운 상황을 그 콩을 가지고있는 주요 맥락의 아이를 만들 필요가 : 여기

는 XML의 추출물이다. 이것은 인바운드 엔드 포인트에 대해 유사한 기술을 사용할 때 샘플 README에 언급 된 포럼 게시물에서 논의됩니다.

그런 다음 상위 컨텍스트의 모든 bean을 배선 할 수 있습니다.

+0

감사합니다. Gary. 게시물에서 새로운 동적 컨텍스트를 만들 때 부모 컨텍스트를 제공해야한다는 것을 이해합니다. 부모가 될 기본 applicationContext.xml은 어떻게 얻습니까? 샘플을 가르쳐 주시겠습니까? – alan

+0

일부 연구 후 나는 ApplicationContextAware를 구현하고 부모 응용 프로그램 컨텍스트에 액세스 할 수 있다고 생각했습니다. – alan

+0

또한'@ApplicationContext'를'@ Autowire '할 수 있습니다. –

관련 문제