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