2

I am trying to watch a folder tree for new files, and it seems like WatchServiceDirectoryScanner is exactly what I need, but I can't get the configuration to start without a locker without throwing a BeanCreationException. How do I tell it I don't want a locker?

<bean id="myScanner" class="org.springframework.integration.file.WatchServiceDirectoryScanner">
    <constructor-arg value="/my/path"/>
    <property name="filter" ref="onceFilter"/>
    <property name="locker"><null/></property>
</bean>
<bean id="onceFilter" class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/>

I don't want to lock files. Do I really need to implement a custom NonLockingLocker?

Buddha Buddy
  • 148
  • 8
  • I have tried implementing a null-op AbstractFileLockerFilter, but I am still getting the same exception. prevent-duplicates is NOT set. Does filename-pattern cause a similar issue? org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFileAdapter.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.WatchServiceDirectoryScanner@7b12e52f – Buddha Buddy Nov 13 '15 at 23:24
  • OK, so filename-pattern DOES cause a similar issue as prevent-duplicates, so neither can be used on a inbound-channel-adapter that uses a scanner, and apparently you DO have to create a null-op AbstractFileLockerFilter. – Buddha Buddy Nov 13 '15 at 23:29

1 Answers1

3

See log message:

The 'filter' and 'locker' options must be present on the provided external 'scanner': org.springframework.integration.file.WatchServiceDirectoryScanner@7b12e52f

That says that you have not to use filter (filename-pattern etc.) and locker options on the <int-file:inbound-channel-adapter>, if you use scanner option.

So, just move their references to the WatchServiceDirectoryScanner. Of course, if you don't have locker, there is no reason to create some NoOpLocker. Just don't declare <property name="locker"> on the WatchServiceDirectoryScanner bean definition.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118