【问题标题】:Configuring System property in Spring在 Spring 中配置系统属性
【发布时间】:2011-12-02 01:55:50
【问题描述】:

我有文件通道适配器,它需要以指定的时间间隔收听目录。我有以下代码。

<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:C:/temp/finalize/)替换directory="file:${SYS.com.abc.wls.workdir}/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>

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

【问题讨论】:

    标签: java spring properties system-properties


    【解决方案1】:

    您需要声明一个识别系统属性的弹簧实体。典型的方法是将PropertyPlaceHolderConfigurer 放入您的 Spring 配置中。

    默认模式为SYSTEM_PROPERTIES_MODE_FALLBACK,这意味着配置器未保存的值将作为系统属性查找。可以使用setSystemPropertiesMode 覆盖该模式。

    【讨论】:

    • @约翰·舍伯格。您的意思是我应该在 PropertyPlaceholderConfigure 中将 设置为 SYSTEM_PROPERTIES_MODE_FALLBACK ?
    • @nobody,确保您总共只有 一个 属性占位符。您也可以尝试仅作为参考集directory="${..}",在${ 之前或之后没有任何字符}
    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2012-12-20
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    相关资源
    最近更新 更多