在Spring Boot应用程序中,在入站通道适配器中添加文件时出现以下异常:nio-locker
获得文件锁定

例外:提供的外部“扫描仪”上必须存在“过滤器”和“储物柜”选项

堆栈跟踪 :
启动应用程序时遇到以下错误。设置bean属性“ source”时无法解析对bean“ filesInChannel.adapter.source”的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'filesInChannel.adapter.source'的bean时出错:FactoryBean在对象创建时抛出了异常;嵌套异常是java.lang.IllegalStateException:所提供的外部“扫描器”上必须存在“过滤器”和“储物柜”选项:org.springframework.integration.file.RecursiveDirectoryScanner@358ee631
所提供的外部“扫描仪”上必须存在“过滤器”和“储物柜”选项

<file:inbound-channel-adapter id="filesInChannel"
    directory="file:${base.path}" auto-startup="false" scanner="recursiveScanner" auto-create-directory="true">

      <integration:poller id="poller" max-messages-per-poll="${max.messages.per.poll}" fixed-rate="${message.read.frequency}" task-executor="pollingExecutor">
        <integration:transactional transaction-manager="transactionManager" />
      </integration:poller>
      <file:nio-locker/>
</file:inbound-channel-adapter>


    <bean id="inboundFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
 <constructor-arg>
     <list>
        <bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/>
        <bean class="org.springframework.integration.file.filters.RegexPatternFileListFilter">
            <constructor-arg value="${file.type}"/>
        </bean>
     </list>
 </constructor-arg>
</bean>
       <bean id="recursiveScanner" class="org.springframework.integration.file.RecursiveDirectoryScanner">
    <property name="filter" ref="inboundFilter" />
    </bean>


你能建议一下吗?

最佳答案

您在scanner="recursiveScanner"上执行<file:inbound-channel-adapter>,但是同时使用<file:nio-locker/>子元素。这就是您违反要求并获得该例外的方式。

根据错误消息中的建议,您需要将NioFileLocker引用移至RecursiveDirectoryScanner bean定义中:

<bean id="recursiveScanner" class="org.springframework.integration.file.RecursiveDirectoryScanner">
   <property name="filter" ref="inboundFilter" />
   <property name="locker" ref="nioLocker" />
</bean>

07-26 06:10