【发布时间】:2011-09-27 19:34:48
【问题描述】:
我的 applicationContext.xml 在路径中:
src/main/resources/META-INF/spring
属性文件在路径中:
src/main/resources/messages
我在 web.xml 中加载 spring 上下文如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/applicationContext.xml</param-value>
</context-param>
当我如下配置 MessageSource 和 PropertyPlaceholderConfigurer 时:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:messages/apps.properties</value>
</list>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:messages/ValidationMessages</value>
<value>classpath:messages/app</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
它们都不起作用,只有当我将 classpath 更改为 classpath* 时才起作用
任何想法为什么?
【问题讨论】:
-
你的意思是它不起作用,当你启动你的服务器时是否有某种错误信息?
-
你们是同一个
jar的属性吗?你试过classpath:/messages/apps.properties。注意messages之前的正斜杠 -
@Jsword:在 ClassPathResource.class 中设置断点(在构造函数中)并以调试模式启动 servlet 容器。然后,当 Spring 为这些找不到的文件创建 Resource 对象时,检查正在使用哪个 ClassLoader,哪个 Path 和哪个 Class 用于解析。 @tolitius:当使用
classpath:方案时,Spring 无论如何都会剥离前导斜线。请参见 ClassPathResource(String, ClassLoader) 构造函数。
标签: spring jakarta-ee classpath