我正尝试使用下面的代码从外部属性文件读取。我很确定我有正确的路径设置,但我仍然没有找到文件错误。有什么建议么?这里是我的代码:弹簧外部属性文件;文件未找到异常
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>
随着我的外部文件路径在属性中设置这样的文件中的web应用程序。
#directory on the server where property files will be stored
external.property.directory=C\:\\propfoldername\\
而我得到的错误是这样的:
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)
任何帮助,将不胜感激。如果我遗漏了一些可能需要查看的代码,请告诉我。
您不能在占位符中使用'PropertyPlaceholderConfigurer' config(spring需要'PropertyPlaceholderConfigurer'来处理'$ {xxx}'vars) – 2014-03-28 18:37:14
你正在试图使用property之前配置它 –