Spring context refering to application context

J

Jani Tiainen

How do you refer to parameters/resources etc. defined in application
context file "context.xml" from Spring "applicationContext.xml" file?

I've only found how you can point to properties file or environment
parameters.

Let's say I've "META-INF/context.xml":

<Context path="/example" reloadable="false">
<Parameter name="exampleParam"
value="123456" override="false" />
</Context>

and in "WEB-INF/applicationContext.xml":

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="ExampleBean" class="com.example.ExampleBean">
<property name="exampleValue">
<value>
<!--
WHAT I ENTER HERE TO GET "exampleParam" VALUE
FROM CONTEXT.XML?!?
-->
</value>
</property>
</bean>
</beans>

so What I need to put in <value /> tag to get value from context.xml?
 
C

Christopher Benson-Manica

[comp.lang.java.programmer] Jani Tiainen said:
How do you refer to parameters/resources etc. defined in application
context file "context.xml" from Spring "applicationContext.xml" file?

Not sure if this solves your problem, because I haven't worked with
parameters and resources, but have you tried
Let's say I've "META-INF/context.xml":
<Context path="/example" reloadable="false">
<Parameter name="exampleParam"
value="123456" override="false" />
</Context>
said:
<bean id="ExampleBean" class="com.example.ExampleBean">

? This should make the definitions in context.xml visible (with no
further qualification) in applicationContext.xml.
 
J

Jani Tiainen

Christopher Benson-Manica kirjoitti:
[comp.lang.java.programmer] Jani Tiainen said:
How do you refer to parameters/resources etc. defined in application
context file "context.xml" from Spring "applicationContext.xml" file?

Not sure if this solves your problem, because I haven't worked with
parameters and resources, but have you tried
Let's say I've "META-INF/context.xml":
<Context path="/example" reloadable="false">
<Parameter name="exampleParam"
value="123456" override="false" />
</Context>
<bean id="ExampleBean" class="com.example.ExampleBean">

? This should make the definitions in context.xml visible (with no
further qualification) in applicationContext.xml.

I've feeling that there is much simpler solution since as I understood
context.xml should be already populated in application before spring
kicks off. Therefore I suspect that there is (simple) way to retrieve
values from already populated context.

I just need to find out how. Importing resource that is already part of
application sounds very bad hack.
 
J

Jani Tiainen

Jani Tiainen kirjoitti:
Christopher Benson-Manica kirjoitti:
[comp.lang.java.programmer] Jani Tiainen said:
How do you refer to parameters/resources etc. defined in application
context file "context.xml" from Spring "applicationContext.xml" file?

Not sure if this solves your problem, because I haven't worked with
parameters and resources, but have you tried
Let's say I've "META-INF/context.xml":
<Context path="/example" reloadable="false">
<Parameter name="exampleParam"
value="123456" override="false" />
</Context>
<bean id="ExampleBean" class="com.example.ExampleBean">

? This should make the definitions in context.xml visible (with no
further qualification) in applicationContext.xml.

I've feeling that there is much simpler solution since as I understood
context.xml should be already populated in application before spring
kicks off. Therefore I suspect that there is (simple) way to retrieve
values from already populated context.

I just need to find out how. Importing resource that is already part of
application sounds very bad hack.

Well, replying to myself, correct way to do is:

<bean id="propertyConfigurer"
class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"
/>

More info can be found from that class documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top