Spring context refering to application context

Discussion in 'Java' started by Jani Tiainen, Aug 24, 2007.

  1. Jani Tiainen

    Jani Tiainen Guest

    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?
    --

    Jani Tiainen
     
    Jani Tiainen, Aug 24, 2007
    #1
    1. Advertising

  2. [comp.lang.java.programmer] Jani Tiainen <> wrote:

    > 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.

    --
    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.
     
    Christopher Benson-Manica, Aug 24, 2007
    #2
    1. Advertising

  3. Jani Tiainen

    Jani Tiainen Guest

    Christopher Benson-Manica kirjoitti:
    > [comp.lang.java.programmer] Jani Tiainen <> wrote:
    >
    >> 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.


    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.

    --

    Jani Tiainen
     
    Jani Tiainen, Aug 27, 2007
    #3
  4. Jani Tiainen

    Jani Tiainen Guest

    Jani Tiainen kirjoitti:
    > Christopher Benson-Manica kirjoitti:
    >> [comp.lang.java.programmer] Jani Tiainen <> wrote:
    >>
    >>> 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.

    >
    > 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.

    --

    Jani Tiainen
     
    Jani Tiainen, Aug 27, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmljayBaZHVuaWM=?=

    Refering to web page class from another class

    =?Utf-8?B?TmljayBaZHVuaWM=?=, Feb 8, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    441
    Karl Seguin [MVP]
    Feb 8, 2006
  2. rmn190
    Replies:
    2
    Views:
    2,397
    Arne Vajhøj
    Jan 10, 2008
  3. kamiseq
    Replies:
    1
    Views:
    388
    kamiseq
    Oct 20, 2008
  4. kamiseq
    Replies:
    0
    Views:
    267
    kamiseq
    Oct 20, 2008
  5. Goldfish
    Replies:
    1
    Views:
    769
    Goldfish
    Nov 6, 2008
Loading...

Share This Page