我有文件通道适配器,需要按指定的间隔监听目录。我有以下代码。
<file:inbound-channel-adapter id="fileAdapter"
directory="file:${SYS.com.abc.wls.workdir}/finalize/" queue-size="1000"
auto-startup="true" filename-pattern="*.txt">
<int:poller fixed-delay="500">
</int:poller>
</file:inbound-channel-adapter>
当我使用真实目录名称(例如
directory="file:${SYS.com.abc.wls.workdir}/finalize/
)替换directory="file:C:/temp/finalize/
时,一切正常。但是在启动服务器时正在设置系统属性,但是spring无法检测到系统属性。能否请你帮忙 ?
更新:
我有以下占位符配置
<beans:bean id="jobProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="properties">
<beans:value>
job.group.commit.interval=5000
</beans:value>
</beans:property>
<beans:property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_FALLBACK" />
<beans:property name="ignoreUnresolvablePlaceholders"
value="true" />
<beans:property name="order" value="1" />
</beans:bean>
已从
file:
中删除directory="file:${SYS.com.abc.wls.workdir}/finalize/"
并更改为auto-create-directory="false"
,现在我得到如下异常, by: java.lang.IllegalArgumentException: Source directory **[${SYS.com.abc.wls.workdir}\finalize] does not exist**.
at org.springframework.util.Assert.isTrue(Assert.java:65)
at org.springframework.integration.file.FileReadingMessageSource.onInit(FileReadingMessageSource.java:233)
at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:98)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.initSource(FileReadingMessageSourceFactoryBean.java:153)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:99)
at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:37)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$2.run(FactoryBeanRegistrySupport.java:133)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:131)
... 63 more
最佳答案
您需要声明一个可以识别系统属性的弹簧实体。典型的方法是在您的Springconfiguration中放置PropertyPlaceHolderConfigurer
。
默认模式为SYSTEM_PROPERTIES_MODE_FALLBACK
,这意味着配置器未保存的值将被视为系统属性。可以使用setSystemPropertiesMode
覆盖该模式。