Java,Spring,找不到/WEB-INF/Spring.properties我需要在PropertyConfigure之外的其他地方设置它吗?

Java,Spring,找不到/WEB-INF/Spring.properties我需要在PropertyConfigure之外的其他地方设置它吗?,java,spring,properties,classpath,Java,Spring,Properties,Classpath,我收到一条错误消息,无法加载属性;嵌套异常为java.io.FileNotFoundException:无法打开类路径资源[WEB-INF/spring.properties],因为它不存在。spring.properties文件确实存在,并且在我的/WEB-INF目录中(我已经确认在构建项目后它在我的构建目录中)。我将其设置在项目的.classpath目录中,如下所示: <classpathentry kind="src" path="src/main/webapp/WEB-INF/sp

我收到一条错误消息,
无法加载属性;嵌套异常为java.io.FileNotFoundException:无法打开类路径资源[WEB-INF/spring.properties],因为它不存在
。spring.properties文件确实存在,并且在我的/WEB-INF目录中(我已经确认在构建项目后它在我的构建目录中)。我将其设置在项目的.classpath目录中,如下所示:

<classpathentry kind="src" path="src/main/webapp/WEB-INF/spring.properties"/>
<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/spring.properties" />
</bean> 

在我的Spring应用程序上下文中,我将其输入如下:

<classpathentry kind="src" path="src/main/webapp/WEB-INF/spring.properties"/>
<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/spring.properties" />
</bean> 


我很抱歉,如果这是一个基本的问题,但我真的很困惑,问题是什么以及如何解决它,我已经做了很多研究,但似乎无法找出它。感谢您的建议

尝试将文件置于
WEB-INF/classes/
下,并使用
value=“spring.properties”
引用它。我认为应该这样做。

看看我的一个使用
属性PlaceHolderConfigure
的WEB应用程序,我发现我将属性放在
/WEB-INF/classes
中,然后将PPC配置为与Spring
类路径一起使用:
URL;i、 e

    /WEB-INF/classes/substitution.properties
作为访问

    classpath:substitution.properties
您的路径(“src/main/webapp”)表明您正在使用Maven构建项目。如果是这种情况,请将.properties-文件放到/src/main/resources并使用“
classpath:
”来访问它们,src/main/resources下的所有内容都应该可以通过classpath进行访问,而无需任何进一步的配置。

Spring支持a,您可以通过完全取消资源前缀来使用它。“您将获得适合于该特定应用程序上下文的资源类型”,并且由于我们使用的是web上下文,因此该资源将是ServletContextResource

路径来自您的webapp的根目录。我们的道路看起来像

 <context:property-placeholder location="/WEB-INF/spring/appServlet/application.properties"/>

只需将spring.properties文件放在src/main/webapp目录下(与WEB-INF一起),并用

<bean id="placeholderConfig"   
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
        <value>spring.properties</value>
    </list>
    </property>
</bean>

斯普林酒店

感谢您的回复,我这样做了,现在得到了
[ERROR][main 11:00:33](ContextLoader.java:initWebApplicationContext:220)上下文初始化失败org.springframework.beans.factory.BeanInitializationException:无法加载属性;嵌套异常是java.io.FileNotFoundException:无法打开ServletContext资源[/spring.properties]
我对此感到有点困惑