Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Spring context refering to application context

Thread view: 
Jani Tiainen - 24 Aug 2007 08:27 GMT
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?
Signature


Jani Tiainen

Christopher Benson-Manica - 24 Aug 2007 15:12 GMT
> 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>

> <beans>
     <!-- This doesn't strike me as appetizing, but might work -->
     <import resource="../META-INF/context.xml"/>
>     <bean id="ExampleBean" class="com.example.ExampleBean">

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

Signature

 C. Benson Manica    | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
  sdf.lonestar.org   | Google groups, due to rampant unchecked spam.

Jani Tiainen - 27 Aug 2007 05:48 GMT
Christopher Benson-Manica kirjoitti:

>> How do you refer to parameters/resources etc. defined in application
>> context file "context.xml" from Spring "applicationContext.xml" file?
[quoted text clipped - 16 lines]
> ?  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.

Signature

Jani Tiainen

Jani Tiainen - 27 Aug 2007 08:24 GMT
Jani Tiainen kirjoitti:
> Christopher Benson-Manica kirjoitti:
>>
[quoted text clipped - 26 lines]
> 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.

Signature

Jani Tiainen



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.