2013-01-24 67 views
0

我想构建一个独立的基于Spring的Java应用程序。Spring上下文:找不到属性占位符文件

我正在使用Maven程序集插件来构建带有依赖项的JAR。该JAR的谢灵运最终看起来像这样(只是一个子集):

com 
META-INF 
org 
properties 
- taskexecutor.properties 
spring 
- properties.xml 
. 
. 
. 

清单如下:

Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver 
Created-By: Apache Maven 
Built-By: authorname 
Build-Jdk: 1.6.0_30 
Main-Class: com.company.utilities.task.TaskLauncher 

当应用程序运行的属性占位符应包括属性进行配置。 xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 

    <context:property-placeholder location="classpath:/properties/taskExecutor.properties"/> 

</beans> 

它运行正常在Eclipse中,但是当我运行jar我得到这个错误:

Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileN 
otFoundException: class path resource [properties/taskExecutor.properties] cannot be opened because it does not exist 
     at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78) 
     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663) 
     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
     at com.company.utilities.task.TaskLauncher.main(TaskLauncher.java:28) 
Caused by: java.io.FileNotFoundException: class path resource [properties/taskExecutor.properties] cannot be opened because it does not exist 
     at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) 
     at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181) 
     at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161) 
     at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:69) 
     ... 6 more 

有什么想法?

回答

0

似乎通过命令行运行是大小写敏感的,但是Eclipse是不加载这些资源时。

更名taskexecutor.propertiestaskExecutor.properties修复了这个问题。哎呀。希望这可以帮助别人像将来一样愚蠢;-)

0

移动taskExecutor.properties根和尝试

<context:property-placeholder location="taskExecutor.properties"/> 
相关问题