Spring integration 调度程序没有ftp订阅服务器错误

Spring integration 调度程序没有ftp订阅服务器错误,spring-integration,Spring Integration,我有一个文件放置在ftp位置,应该由ftp入站适配器拾取。此文件保存到本地目录。spring文件入站适配器依次轮询此本地目录。FileNameGeneratorbean用于文件入站适配器中,并动态决定目标。我还发布了另一个关于本地目录中的文件未被删除的问题。这就是我面临的问题。 这是我的整个配置 <util:properties id="someid" location="classpath:config/config.properties"/> &l

我有一个文件放置在ftp位置,应该由ftp入站适配器拾取。此文件保存到本地目录。spring文件入站适配器依次轮询此本地目录。FileNameGeneratorbean用于文件入站适配器中,并动态决定目标。我还发布了另一个关于本地目录中的文件未被删除的问题。这就是我面临的问题。 这是我的整个配置

        <util:properties id="someid" location="classpath:config/config.properties"/>
        <mvc:annotation-driven />

    <context:component-scan base-package="com.dms" />
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix">
                <value>/WEB-INF/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>
         <context:property-placeholder location="classpath:config/jdbc.properties,classpath:config/config.properties,classpath:config/ftp.properties"/>
          <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource"
            >
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            </bean>
         <bean id="sessionFactory"
                class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

                <property name="dataSource">
                      <ref bean="dataSource" />
                </property>

                <property name="hibernateProperties">
                      <props>
                            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
                      </props>
                </property>
                <property name="packagesToScan">
                <list>
                    <value>com.dms.entity</value>
                </list>
            </property>
                </bean>
                <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

         <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

             <!-- setting maximum upload size -->
            <property name="maxUploadSize" value="10485760" />

        </bean>
        <!-- scheduler to pickup temp folder files to permanent location -->

        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                 <property name="triggers">
                        <list>
                             <ref bean="simpleTrigger" /> 

                        </list>
                 </property>
          </bean>
         <bean id="dmsFilesDetectionJob" class="com.dms.scheduler.job.DMSFilesDetectionJob">

         </bean>
         <bean id="dmsFilesDetectionJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="dmsFilesDetectionJob" />
            <property name="targetMethod" value="pollTempFolder" />
            <property name="concurrent" value="false" />
         </bean>
        <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="dmsFilesDetectionJobDetail" />
            <!-- <property name="cronExpression" value="1 * * * * ?" /> --> 
            <property name="cronExpression" value="0 0/1 * * * ?" /> 
         </bean>

      <bean id="fileNameGenerator" class="com.dms.util.FileNameGenerator"/>   
        <int-file:inbound-channel-adapter id="filesIn" directory="file:${paths.root}" channel="abc" filter="compositeFilter" >
            <int:poller id="poller" fixed-delay="5000" />

        </int-file:inbound-channel-adapter>
        <int:channel id="abc"/>
        <bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
            <constructor-arg>
                <list>
                    <!-- Ensures that the file is whole before processing it -->
                    <bean class="com.dms.util.CustomFileFilter"/>
                    <!-- Ensures files are picked up only once from the directory -->
                    <bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
                </list>
            </constructor-arg>
        </bean> 
        <int-file:outbound-channel-adapter channel="abc" id="filesOut"
            directory-expression="@outPathBean.getPath()"
            delete-source-files="true" filename-generator="fileNameGenerator" />
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <ref bean="jsonMessageConverter"/>
                </list>
            </property>
        </bean>
        <bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
         <!-- <property name="prefixJson" value="false"/> -->
          <!-- <property name="objectMapper">
                <bean class="com.dms.util.HibernateAwareObjectMapper" />
            </property> -->
            <property name="supportedMediaTypes" value="application/json"/>
        </bean>   
        <bean id="ftpClientFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="${ftp.ip}"/>
        <property name="port" value="${ftp.port}"/>
        <property name="username" value="${ftp.username}"/>
        <property name="password" value="${ftp.password}"/>
        <property name="clientMode" value="0"/>
        <property name="fileType" value="2"/>
        <property name="bufferSize" value="100000"/>
    </bean>
            <int-ftp:outbound-channel-adapter id="ftpOutbound"
    channel="ftpChannel"
    session-factory="ftpClientFactory"
    charset="UTF-8"
    remote-file-separator="/"
    auto-create-directory="true"
    remote-directory="." 
    use-temporary-file-name="true"
   auto-startup="true" 
    />  
<int-ftp:inbound-channel-adapter id="ftpInbound"
    channel="ftpChannel"
    session-factory="ftpClientFactory"
    charset="UTF-8"
    local-directory="file:${paths.root}"
    delete-remote-files="true"
    temporary-file-suffix=".writing"
    remote-directory="."
    filename-pattern="${file.char}*${file.char}"

    preserve-timestamp="true"
     auto-startup="true">
    <int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>
        <int:channel id="ftpChannel" /> 
此异常并非每次都出现。 如您所见,我添加了auto startup=“true”。已为通道和适配器使用了唯一id。请让我知道这里出了什么问题


谢谢

首先,您的集成流程不清楚。但我知道你的问题是为了这个

<int-ftp:inbound-channel-adapter id="ftpInbound" channel="ftpChannel"
默认情况下,
阶段
0
,因此入站通道适配器可以在出站通道适配器之前启动


或者升级到最新版本

我只需要处理这个问题,但需要使用一个文件入站通道适配器。该问题是间歇性的,仅在启动时出现。我认为带有轮询器的适配器可以在Spring集成完全初始化之前开始引入消息

我的修复方法是在启动时禁用适配器。适配器的详细信息并不重要,只是它有一个id,并且设置为“非自动启动”:

  <!--
    Read files from an "inbox" directory, placing them on an "inbox" channel...
  -->

  <int-file:inbound-channel-adapter id="inboxScanner"
                                    directory="$import{inbox}"
                                    auto-create-directory="true"
                                    channel="fileInbox"
                                    prevent-duplicates="false"
                                    auto-startup="false">
    <int:poller fixed-rate="$import{inbox.scan.rate.seconds}"
                time-unit="SECONDS"
                max-messages-per-poll="$import{inbox.max.imports.per.scan}"/>
  </int-file:inbound-channel-adapter>

然后,我点击Spring的应用程序生命周期事件,一旦创建(或刷新)完应用程序上下文,我就告诉适配器开始:

  <!--
    Only start the scanner after the application has finished initializing...
  -->

  <int-event:inbound-channel-adapter event-types="org.springframework.context.event.ContextRefreshedEvent"
                                 channel="contextRefreshEvents"/>

  <int:publish-subscribe-channel id="contextRefreshEvents"/>

  <int:outbound-channel-adapter channel="contextRefreshEvents"
                                expression="@inboxScanner.start()" />


“事件”组件来自spring integration event。

是否应该有一个单独的通道,其中ftpinbound适配器从中读取,ftp出站写入?此异常也不一致。现在它运行没有任何问题,这是伟大的,你解决了一个问题,你赢了。如果我的回答有帮助,请接受它,将问题标记为已结束。我已编辑q以添加我的完整配置,因为您说流程不清楚。我还将其更改为对入站和出站使用相同的通道。如果我必须更改配置中的任何内容,请告诉我。我将观察应用程序运行几次,然后得出结论,频道更改是解决方案。请在我的回答中找到
编辑
。希望对您有所帮助。请查看我答案中的
编辑
。您的解决方案很好,但有一个更简单的技巧-调整
阶段。我将在这里留下我的答案,但听起来真正的答案是升级!感谢您指出这一点:-)
  <!--
    Read files from an "inbox" directory, placing them on an "inbox" channel...
  -->

  <int-file:inbound-channel-adapter id="inboxScanner"
                                    directory="$import{inbox}"
                                    auto-create-directory="true"
                                    channel="fileInbox"
                                    prevent-duplicates="false"
                                    auto-startup="false">
    <int:poller fixed-rate="$import{inbox.scan.rate.seconds}"
                time-unit="SECONDS"
                max-messages-per-poll="$import{inbox.max.imports.per.scan}"/>
  </int-file:inbound-channel-adapter>
  <!--
    Only start the scanner after the application has finished initializing...
  -->

  <int-event:inbound-channel-adapter event-types="org.springframework.context.event.ContextRefreshedEvent"
                                 channel="contextRefreshEvents"/>

  <int:publish-subscribe-channel id="contextRefreshEvents"/>

  <int:outbound-channel-adapter channel="contextRefreshEvents"
                                expression="@inboxScanner.start()" />