1
votes

In Spring boot application, Getting below exception when added file:nio-locker in inbound-channel-adapter to obtain file-locking

Exception : The 'filter' and 'locker' options must be present on the provided external 'scanner'

Stack trace : facing below error while starting the application.Cannot resolve reference to bean 'filesInChannel.adapter.source' while setting bean property 'source'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filesInChannel.adapter.source': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: The 'filter' and 'locker' options must be present on the provided external 'scanner': org.springframework.integration.file.RecursiveDirectoryScanner@358ee631
The 'filter' and 'locker' options must be present on the provided external 'scanner

<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>

could you please suggest on this.

1

1 Answers

2
votes

You do scanner="recursiveScanner" on the <file:inbound-channel-adapter>, but at the same time you use <file:nio-locker/> sub-element. That's how you violate a requirements and get that exception.

According a recommendation in the error message you need to move a NioFileLocker reference into the RecursiveDirectoryScanner bean definition instead:

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