2

我需要从属性文件动态加载 @scheduled 注释的 cron 表达式。我知道解决方案是使用属性占位符,但我的问题是,可以动态修改包含 cron 表达式的属性文件,并且它的位置来自另一个属性文件。

application-context.xml 看起来像这样,

    <util:properties id="dynamicProps" location="${configurable.property.file.path}"
    <context:property-placeholder properties-ref="dynamicProps"  />

可配置的.property.file.path 属性存在于位于 WEB-INF/classes 下的属性文件中,其值类似于这样,

 configurable.property.file.path=${static.assets.path}/config/configuration.properties

使用上述设置启动服务器婴儿床时出现以下错误,

  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#1': Cannot resolve reference to bean 'dynamicProps' while setting bean property 'properties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicProps': Invocation of init method failed; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/${configurable.property.file}]

我猜这可能是因为此时属性文件还不可见。解决方案是什么?有人可以帮我吗?

4

0 回答 0