Java spring外部属性文件;找不到文件异常

Java spring外部属性文件;找不到文件异常,java,xml,spring,javabeans,Java,Xml,Spring,Javabeans,我试图用下面的代码从外部属性文件中读取。我非常确定我的路径设置正确,但我仍然得到文件未找到错误。有什么建议吗?这是我的密码: public class Timer { @Autowired private ApplicationContext ctx; @Autowired private SpringMailSender springMailSender; @Scheduled(cron="${timer.time}") //thi

我试图用下面的代码从外部属性文件中读取。我非常确定我的路径设置正确,但我仍然得到文件未找到错误。有什么建议吗?这是我的密码:

public class Timer {

     @Autowired
      private ApplicationContext ctx;

     @Autowired
        private SpringMailSender springMailSender;

    @Scheduled(cron="${timer.time}") //this is the line that is having trouble
    public void timer()
    {
        System.out.println("timer() in Timer Class has been stepped into");
        try {
            springMailSender.sendMail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        System.out.println("Method executed on every 2nd Monday of each month. Current time is :: "+ new Date());
    }

}
下面是我如何为它设置配置文件

<!--  Property Placeholder -->
        <bean
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:properties/system.properties</value>
                    <value>file:${external.property.directory}propfilename</value>
                </list>
            </property>
        </bean>

<!-- messageSource -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>file:${external.property.directory}propfilename</value>
            </list>
        </property>
    </bean>
我得到的错误是:

 org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: ${external.property.directory}propfilename (The system cannot find the file specified)

任何帮助都将不胜感激。如果我遗漏了一些您可能需要查看的代码,请告诉我。

由于${external.property.directory}无法解析,您尝试执行的操作无法正常工作。
但是,如果同时需要两个属性文件,可以使用环境变量获得相同的结果(请注意,第二个文件中的任何属性都将覆盖第一个文件中的相同属性)

您不能在
propertyplaceholderconfigure
config中使用占位符(spring需要
PropertyPlaceHolderConfigure
来处理
${xxx}
vars)您试图在配置iThanks之前使用属性。我只是将外部属性行放在我的内部属性文件中,这就解决了它。
 org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: ${external.property.directory}propfilename (The system cannot find the file specified)