java - Niolocker - 'filter' 和 'locker' 选项必须出现在提供的外部 'scanner' 上

标签 java spring-boot locking spring-integration nio

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

异常(exception):“过滤器”和“储物柜”选项必须出现在提供的外部“扫描仪”上

堆栈跟踪: 启动应用程序时遇到以下错误。设置 bean 属性“source”时无法解析对 bean“filesInChannel.adapter.source”的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“filesInChannel.adapter.source”的 bean 时出错:FactoryBean 在对象创建时抛出异常;嵌套异常是 java.lang.IllegalStateException: 'filter' 和 'locker' 选项必须出现在提供的外部 'scanner' 上: 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>

关于java - Niolocker - 'filter' 和 'locker' 选项必须出现在提供的外部 'scanner' 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51842921/

相关文章:

Java输入字母

java - 确定 JavaFX 字体的宽度和高度

java - Spring Boot集成XXE预防设置

c# - 在 ASP.NET MVC 应用程序中锁定一个全局对象时是否可能出现死锁?

c# - 限制单次执行一个方法的线程数

java - 即使我使用的是 Locale.US,点也会返回 MisMatch 异常

java - OpenERP Jasper Reports导入外部库

java - Jersey MultiPartRequest 接收 null

java - 在这个 Spring Boot\MVC Controller 中处理 REST 样式映射的正确方法是什么?

表上的 MySQL 永久锁定