Java 如何使用Spring2.5.x访问父类路径上的资源?

Java 如何使用Spring2.5.x访问父类路径上的资源?,java,spring,classpath,classloader,Java,Spring,Classpath,Classloader,在我的WebSpherePortal环境中,我试图配置一个bean,该bean使用WAR之外的资源(它位于WAS的某个父类路径中)。 我确信它就在那里,因为我可以通过以下方式访问它: URL url = getClass().getResource("/config/someProps.properties"); 但是,在我的Spring applicationContext.xml中,以下内容不起作用: <bean id="initBean" class="foo.PropInitia

在我的WebSpherePortal环境中,我试图配置一个bean,该bean使用WAR之外的资源(它位于WAS的某个父类路径中)。 我确信它就在那里,因为我可以通过以下方式访问它:

URL url = getClass().getResource("/config/someProps.properties");
但是,在我的Spring applicationContext.xml中,以下内容不起作用:

<bean id="initBean" class="foo.PropInitializer">
    <constructor-arg value="classpath:/config/someProps.properties"/>   
</bean>

如果我删除“classpath:”,那也没什么帮助

目前,我正在使用ContextLoaderListener加载Spring上下文,但似乎Spring无法访问/使用父类路径


有没有办法(使用Spring配置)也加载父类路径?

尝试传递类路径*:而不是类路径:

<bean id="initBean" class="foo.PropInitializer">
    <constructor-arg value="classpath*:/config/someProps.properties"/>   
</bean>
<bean name="applicationConfig" class="foo.io.ResourceLoader">
    <constructor-arg value="/config/someProps.properties" />
</bean>

你可以找到更详细的解释。

我已经设法(某种程度上)解决了我的问题

我最终创建了一个工厂类,可用于从类路径加载资源:

<bean id="initBean" class="foo.PropInitializer">
    <constructor-arg value="classpath*:/config/someProps.properties"/>   
</bean>
<bean name="applicationConfig" class="foo.io.ResourceLoader">
    <constructor-arg value="/config/someProps.properties" />
</bean>

这是基于现有的Spring类:
org.springframework.core.io.ClassPathResource

不幸的是,Spring类在我的情况下不能很好地工作(我在将结果bean传递到的方法中遇到了一些属性模糊问题),这就是为什么我创建了自己的类来返回确切的类型


在任何情况下,我希望使用Springs
ClassPathResource
在大多数情况下都能工作。

遗憾的是,我仍然得到以下信息:java.io.FileNotFoundException:classpath*:/config/someProps.properties我们可以看到
foo.PropInitializer
的源代码,或者至少是字段和构造函数吗?