我一直在寻找与Spring PropertyPlaceholderConfigurer
bean和相关类路径相关的问题,但到目前为止一直无法解决我的问题。我正在对名为myApp
的旧程序进行一些更改,该程序作为Jar运行,并且具有名为myApp.properties' file, which lives in a directory called 'config' within my application directory. In the
applicationContext.xml'myApp'的文件的外部属性文件我有一个定义在该外部属性文件中的bean:为Spring PropertyPlaceholderConfigurer bean设置类路径
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:myApp.properties</value>
</list>
</property>
此应用程序构建和NetBeans中运行时工作得很好,因为我包括config
文件夹中的所有JAR依赖关系构建和运行沿。但是,当我尝试使用java -jar myApp.jar
,我得到以下错误的命令行运行它:
08/01/2016 15:37:18.562 | ERROR | Unable to start the application. | org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [myApp.properties] cannot be opened because it does not exist
,我感到我需要正确指定类路径,使Spring知道在哪里可以找到属性文件,但我也不太清楚究竟是如何做到这一点,所以任何指针将不胜感激......
“config”后的'*'是什么意思?我认为这是一个通配符? –
实际上,同时使用-classpath和-jar选项无法解决问题,因为指定的类路径会被忽略,以支持包含在JAR中的manifest.mf文件中的任何内容。所以我所要做的只是使用-classpath并明确指定主类,而不是仅指定JAR –
另外,我在今天下午的SO研究中了解到,'*'专门用于JAR文件(也可能是类文件IIRC),所以使用它不会使程序找到我的属性文件... –