我在我的项目中使用 Spring MVC,我在中定义了详细信息web.xml
像这样 :
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml,
classpath*:/applicationContext-security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
我还定义了一个外部属性文件,我想使用属性文件中的详细信息,所以我定义了一个PropertyPlaceholderConfigurer
豆子在applicationContext.xml
像这样 :
<context:property-placeholder location="classpath*:/system.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
但是当我运行我的项目时,我发现我无法使用属性文件详细信息applicationContext-mvc.xml
,当我也把
<context:property-placeholder location="classpath*:/system.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
in my applicationContext-mvc.xml
,效果很好。也就是说我必须定义PropertyPlaceholderConfigurer
Spring配置xml文件中的所有bean,是吗?
我不明白,ContextLoaderListener
创建根Web应用程序上下文,DispatcherServlet
创建servlet特定的Web应用程序上下文,
Spring MVC中的层次结构是这样的:
它没有说我可以在 Spring MVC 配置文件中使用从根 Web 应用程序上下文扩展的 bean?
我不知道为什么,我是否必须定义PropertyPlaceholderConfigurer
在所有Spring配置文件中?