Results 1 to 5 of 5

Thread: Lazy setting of properties?

  1. #1
    Join Date
    Aug 2004
    Posts
    2,715

    Default Lazy setting of properties?

    Hi all,

    I just wondered if/how it might be possible to lazily set properties.

    Scenario:

    <bean id="A" class="test.A">
    <property name="foo">
    <ref local="B"/>
    </property>
    </bean>

    <bean id="B" class="test.B" lazy-init="true">
    </bean>

    If A is retrieved from the bean factory, B will be instantiated as well.
    Is it somehow possible to assign some kind of lazy proxy for the "foo" property which resolves an actual instance of B on first access?
    I already thought of using TargetSource but didn't find a working solution yet.

    Any help would be appreciated.

    Regards,
    Andreas

  2. #2

    Default

    I guess <lookup-method name="getFoo" bean="B" /> would do what you ask for.

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    As far as I know, this would require me to define the getFoo method abstract and let it be enhanced by CGLIB. That would not exactly be what I am looking for. I rather look for some kind of dynamic "lazy proxy".

    The idea behind is, that I have a standalone application communicating with a remote EJB. Normally, if the app server isn't running and the configuration fails, that is ok. But now there is a new use case which does not require the server. So I tried to find a simple solution to make the realization of the EJB proxy lazy to allow for that use case even in the absence of the application server (without changing the configuration). Since the EJB is never called, everything would work fine.

    Regards,
    Andreas

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    As of about 1.1, in fact the AbstractSlsbInvokerInterceptor from which the ejb proxy inherits has a lookupHomeOnStartup flag which you can set to false (default is true). Additionally, you can even set the cacheHome property to false, which will make the home be looked up each time. Less efficient, but can handle failure...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Thanks Colin
    I didn't realize the introduction of this flag (in fact the initial code used Spring 0.9).
    I think this will solve my problem.

    Andreas

Similar Threads

  1. FlowExecutionStorage in a DB
    By cacho in forum Web Flow
    Replies: 7
    Last Post: Oct 19th, 2009, 03:36 PM
  2. Replies: 9
    Last Post: Aug 8th, 2005, 10:20 AM
  3. setting superclass action properties
    By louiserochford in forum Web
    Replies: 0
    Last Post: May 19th, 2005, 11:42 AM
  4. Setting properties of JNDI Datasource
    By chenrici in forum Data
    Replies: 1
    Last Post: May 13th, 2005, 09:47 AM
  5. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •