gpt4 book ai didi

java - Spring 3.0 无法加载属性

转载 作者:行者123 更新时间:2023-12-03 02:00:34 25 4
gpt4 key购买 nike

我在部署 Web 应用程序时遇到以下错误/异常:

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/WebAppProps]

下面是我在 applicationContext.xml 中使用的上下文标记,指向 WebAppsProps.properties 文件

   <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:/WEB-INF/WebAppProps.properties" />

我也用过:

  <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/WebAppProps.properties" />

该文件实际上位于文件系统中,下面是我的项目结构的快照:

enter image description here

我也尝试过,将“WebAppProps.properties”放在类路径上并使用这两种变体

变体 1:

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

变体 2:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
<property name="location">
<value>WebAppProps.properties</value>
</property>
</bean>

请看下面: enter image description here

但是我仍然遇到相同的错误/异常。

请多多指教

谢谢

最佳答案

我遇到了同样的问题,

修复:解决方案你的bean如下所示:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/database.properties</value>
</property>
</bean>

WEB-INF下创建文件夹属性,它看起来像WEB-INF/properties/database.properties

因为 PropertyPlaceholderConfigurer 类默认搜索 /WEB-INF/ 下的属性文件夹,因此它将您的文件名连接为路径

关于java - Spring 3.0 无法加载属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10627856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com