Results 1 to 3 of 3

Thread: How to know from one bean is another bean already loaded or not?

  1. #1

    Default How to know from one bean is another bean already loaded or not?

    Is it possible to know from one bean is another bean already loaded or not? First bean must to know it becase it's behaviour is different depends on another bean state.

  2. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    Interesting problem if the beans cannot be specified as depended (for use of DI) and you also can't use depends-on.

    Use afterPropertiesSet to set an external resource or state holding bean; use context messages; if client is bean factory aware, query the context to see if the bean is present; add an Introduction to the possiblyLoaded to signal its instantiation; use a custom BeanFactoryPostProcessor to set client bean state.

    But, I'm sure there are better more Springish ways.

  3. #3
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default

    It seems that you might want to do some re-design here.
    Use of strategy interface that encapsulates the changing behaviour vs. figuring out the type at runtime and acting on that.

    If you are not in controll of the injected code, you could wrap it in the delegate interface and use it that way.

    This way you only change configuration vs. adding code to the target bean.

    You could also take a look at implementating a custome "scope" for that type of a bean. 2.0 feature.

    Dmitry

Posting Permissions

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