View Full Version : <context-param>contextConfigLocation in web.xml
scott
May 21st, 2007, 02:00 PM
I saw a section in web.xml
<context-param>
<description>
WebFlow context configuration</description>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/test-context.xml</param-value>
</context-param>
Now the test-context.xml:
<beans>
<bean id="test" class="com.test.project.Test">
<constructor-arg value="java:com/env/jdbc/test
<constructor-arg>
<bean class="com.test.security.User">
<property name="userID" value="0" />
</bean>
</constructor-arg>
</bean>
</beans>
My questions are:
1) "Who" (which class) will use the param-name:contextConfigLocation?
2) "Who" and how to get the id("test") in the application?
3) How to get the bean class User and userID?
Thanks
Scott
Rossen Stoyanchev
May 21st, 2007, 03:18 PM
1) The contextConfigLocation param is used in conjunction with this Spring listener org.springframework.web.context.ContextLoaderListe ner
2) Depends which Web Framework you're using. In Spring MVC you can inject "test" into any controller bean in your ${servletname}_servlet.xml. Or in any environment you can use a class called WebApplicationContextUtils to get to your context and ask it for a bean with the "test" id.
3) In this case the User class is configered as an anonymous bean so you can't use an id to get to it. You could get a reference to it from the Test class assuming that provides a getter for it.
scott
May 21st, 2007, 04:09 PM
Thanks for the help. Though, I have further questions:
1)I just wonder what are the usage of the:
<beans>
<bean id="test" class="com.test.project.Test">
<constructor-arg value="java:com/env/jdbc/test
<constructor-arg>
<bean class="com.test.security.User">
<property name="userID" value="0" />
</bean>
</constructor-arg>
</bean>
</beans>
what is the <constructor-arg and how would it be accessed in a java class?
2)What will happen, if I do not include in the web.xml:
<context-param>
<description>
WebFlow context configuration</description>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/test-context.xml</param-value>
</context-param>
3) In the test-context.xml, there is a comment like this:
This file defines all the flow factories. The configuration of each flow factory
has a configuration file defined by the location property. These configuration
files make references to the form-action beans defined near the bottom.
How to understand the statement (flow factories, configuration file, form-action bean, etc)?
Thanks
Scott
Rossen Stoyanchev
May 21st, 2007, 05:39 PM
The code the Spring container executes for the "test" bean is:
Test test = new Test("java:com/env/jdbc/test", new User());
assuming the Test constructor takes a String and a User. More likely though it takes a DataSource and a user in which case it will look up the JNDI object and supply it as the first parameter instead.
I suggest getting a basic familiarity with Dependency Injection with the Spring container:
http://www.springframework.org/docs/reference/beans.html
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.