我创建了一个我需要在WEB-APP中使用的JAR . 两者都是用spring框架创建的 . 我想在Web应用程序的主上下文中在JAR文件外部加载.properties文件 . 我想用Spring为我们提供的设施来做到这一点 .
我试图在JAR里面的spring.xml文件中做这样的事情:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/classes/my.properties</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="myJob" />
<property name="cronExpression" value="${my.cronExpression}"/>
</bean>
</property>
</bean>
尝试从my.properties文件加载my.cronExpression . 但没有任何成功 .
我总是得到这个错误:
无法解析占位符'my.cronExpression' .
我尝试使用类路径更改多个变体的位置:/ WEB-INF/classes/my.properties等...
但是我无法加载配置文件 .
谢谢你的帮助 .
3 回答
使用classpath:my.properties - / WEB-INF / classes是类路径的根 .
尝试按如下方式声明:
我已经完成了您的代码,并希望您尝试使用此代码段
这对我来说很有效 :)