Java 在Spring中配置系统属性

Java 在Spring中配置系统属性,java,spring,properties,system-properties,Java,Spring,Properties,System Properties,我有一个文件通道适配器,它需要在指定的时间间隔内监听目录。我有下面的代码 <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="5

我有一个文件通道适配器,它需要在指定的时间间隔内监听目录。我有下面的代码

<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/”
中删除:
file:
,并更改为
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

您需要声明一个识别系统属性的spring实体。典型的方法是在Springconfiguration中添加一个


默认模式为
SYSTEM\u PROPERTIES\u mode\u FALLBACK
,这意味着将查找未由配置程序保存的值作为系统属性。可以使用。

@Johan Sjöberg覆盖该模式。你的意思是我应该在PropertyPlaceholderConfigure中设置为SYSTEM\u PROPERTIES\u MODE\u FALLBACK?@无人,请确保您总共只有一个属性占位符。您也可以尝试设置
目录=“${..}”
,在
${
}
之前或之后不使用任何字符,以供参考。
    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