How to skip the setting of 'filter' and 'locker' attribute if custom DirectoryScanner is used in Spring Integration 4.2.0 with XML Config

三世轮回 提交于 2020-02-02 10:10:28

问题


With Spring Integration 4.2.0, it mentioned that 'filter' and 'locker' must be present if custom Scanner is being used (https://jira.spring.io/browse/INT-3619).

I don't know how to set this with XML config if I simply override the listEligibleFiles() method and use the default filters provided by DefaultDirectoryScanner.

e.g.

// using the default filters
public class MyDirectoryScanner extends DefaultDirectoryScanner {
    @Override
    protected File[] listEligibleFiles(File directory) throws IllegalArgumentException {
        return super.listEligibleFiles(directory);
    }
}

<bean id="myCustomScanner"
      class="com.company.MyDirectoryScanner" />

<int-file:inbound-channel-adapter directory="my_directory"
                                  prevent-duplicates="true"
                                  scanner="myCustomScanner"
                                  channel="myChannel">
    <int:poller fixed-rate="10"
                time-unit="SECONDS" max-messages-per-poll="5" />
</int-file:inbound-channel-adapter>

回答1:


It's not clear what you mean; that JIRA was to fix a bug where those properties were incorrectly overridden.

When injecting a custom scanner, you need to set those properties on your scanner rather than via the namespace.




回答2:


use the default filters provided by DefaultDirectoryScanner.

The DefaultDirectoryScanner has the code:

public DefaultDirectoryScanner() {
    final List<FileListFilter<File>> defaultFilters = new ArrayList<FileListFilter<File>>(2);
    defaultFilters.add(new IgnoreHiddenFileListFilter());
    defaultFilters.add(new AcceptOnceFileListFilter<File>());
    this.filter = new CompositeFileListFilter<File>(defaultFilters);
}

So, if you would like do not use AcceptOnceFileListFilter (or any other default) you should follow with the recommendation from the Docs and use setFilter() of the DirectoryScanner contract. For this purpose there is FileListFilterFactoryBean with the setPreventDuplicates() to be set to false.

And yes, remove, please, prevent-duplicates="true" from your configuration, because it is prohibited, when scanner is in use:

Assert.state(!(this.scannerExplicitlySet && (this.filter != null || this.locker != null)),
            "The 'filter' and 'locker' options must be present on the provided external 'scanner': "
                    + this.scanner);

The filter can be set to null on the DefaultDirectoryScanner by the way...

I'm converting the JIRA to Documentation just to be more clear on the matter.



来源:https://stackoverflow.com/questions/32583113/how-to-skip-the-setting-of-filter-and-locker-attribute-if-custom-directorysc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!