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