I use Spring MVC in my project, I define the details in web.xml
like this :
<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>
I also define a external properties file, I want use the details in the properties file, so I define a PropertyPlaceholderConfigurer
bean in applicationContext.xml
like this :
<context:property-placeholder location="classpath*:/system.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
but when i run my project, I find that I can't use the properties file details in applicationContext-mvc.xml
, when I also put the
<context:property-placeholder location="classpath*:/system.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
in my applicationContext-mvc.xml
, it works well。 That is say I must define PropertyPlaceholderConfigurer
bean in all Spring configuration xml file, it is right?
I do not understand, the ContextLoaderListener
create the root web application context, the DispatcherServlet
create the servlet-specifical web application context,
the hierarchy in Spring MVC like this:
it didn't say that I could use the bean extends from root web application context in Spring MVC configuration file?
I don't know why, whether I must define PropertyPlaceholderConfigurer
in all Spring configuration file?