在 Spring 中配置系统属性

发布于 2024-12-08 08:24:21 字数 2536 浏览 1 评论 0 原文

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

<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: from 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

I have file channel adapter which need to listen to a directory in specfied intervals. And I have the following code.

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

when I replce directory="file:${SYS.com.abc.wls.workdir}/finalize/ with a real directory name ( like directory="file:C:/temp/finalize/) everything works fine. But the system property is being set when starting the server, but spring doesnt detect the system property.

Could you please help ?

Update :

I have the following configuration for place holder

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

Removed : file: from directory="file:${SYS.com.abc.wls.workdir}/finalize/" and changed to auto-create-directory="false" and now I'm gettign the exception as below,

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-12-15 08:24:21

您需要声明一个识别系统属性的 spring 实体。典型的方法是放置 PropertyPlaceHolderConfigurer

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

You need to declare a spring entity which recognizes system properties. The typical approach is to put a PropertyPlaceHolderConfigurer in your Springconfiguration.

The default mode is SYSTEM_PROPERTIES_MODE_FALLBACK, which means that values not held by the configurer will be looked for as a system property. The mode can be overriden using setSystemPropertiesMode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文