我有一个WAR包。
这个问题与一个老问题非常相似,但解决方案对我没有用。
在web.xml
中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
在 application-context.xml
文件中。<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:social.properties</value>
</property>
</bean>
但是我得到了这个:
org.springframework.beans.factory.BeanInitializationException: 无法加载属性;嵌套异常为 java.io.FileNotFoundException: 无法打开 ServletContext 资源 [/social.properties]
我检查了WAR包 - .xml
和 .properties
文件都在 /WEB-INF/classes
下
.properties
文件在 src/main/resources
中,.xml
文件在 src/main/java
中(两者都在默认包中),而Maven 工具将它们正确地传输到 WEB-INF/classes
的默认包中(我认为)
有谁知道为什么我会收到这个异常?谢谢。
编辑:我只想补充说,JUnit 测试通过了(我的意思是它们从 social.properties
加载了应该加载的内容),但运行应用程序时它忽略了我的 classpath:
前缀。
classpath:
前缀实际上存在吗? - axtavt/home/...-DEVELOPMENT-0.0.1.war
构建成功。当我打开 war 文件并查看/WEB-INF/classes/application-context.xml
时,我看到了classpath:
前缀。 - kuncajs