PropertyPlaceholderConfigurer找不到

PropertyPlaceholderConfigurer找不到

本文介绍了春季:PropertyPlaceholderConfigurer找不到属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用PropertyPlaceholderConfigurer的Spring有一个奇怪的问题.我的一颗豆的设计如下:

I have a strange problem with Spring using PropertyPlaceholderConfigurer. One of my beans is designed as follow :

<bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>classpath:jdbc.properties</value>
    </property>
</bean>

问题是spring永远找不到jdbc.properties(FileNotFoundException).该文件位于捆绑包类路径中的名为"resources"的文件夹中(我在OSGi项目中工作).

The problem is that spring never find jdbc.properties (FileNotFoundException). The file is in a folder named "resources" that is in the bundle classpath (I am working in a OSGi project).

我尝试了几乎所有组合("jdbc.properties","/jdbc.properties","classpath:jdbc.properties","classpath:/jdbc.properties","/resources/jdbc.properties"等) ...),但是它永远都行不通.

I have tried almost every combination ("jdbc.properties", "/jdbc.properties", "classpath:jdbc.properties", "classpath:/jdbc.properties", "/resources/jdbc.properties", etc...) but it never works.

有关信息,如果有的话,我会做类似的事情:

For information, if at some point, I do something like :

URL u = someClassLoader.getResource("jdbc.properties");

它确实可以正常工作并找到文件.实际上,我完全无法理解spring的错误.

it does work without any problem and find the file. Actually I am totally unable to understand what is the bug with spring.

如果您有任何帮助的想法,请先谢谢.我在春天不是很有经验,所以我可能在某个地方犯了一个错误.

If you have any idea to help me, thanks in advance. I am not very experienced in spring so I have maybe done a mistake somewhere.

实际上,这是类加载器的问题:如果我这样做:

Actually, it's a problem of classloader :If I do :

new ClassPathResource("jdbc.properties");

它不起作用.但是:

new ClassPathResource("jdbc.properties",someClassIntheBundle.class.getClassLoader());

工作完美.

我确实相信Spring使用它自己的包所消耗的ClassLoader.您知道解决这个棘手问题的方法吗?

I do believe that Spring use the ClassLoader of its own bundle that is consumed by my bundle. Do you know a way to solve this tricky problem ?

谢谢

推荐答案

尝试classpath*:jdbc.properties

这篇关于春季:PropertyPlaceholderConfigurer找不到属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:27