Results 1 to 3 of 3

Thread: Circular Dependency Nightmare

  1. #1
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    46

    Default Circular Dependency Nightmare

    We have an service based architecture and have recently been moving our transaction handling up from the DAO layer to the service layer. While doing this, I found a very nasty circular dependency that wasn't there before.

    I have a Catalog Service object that is the target of a TransactionFactoryProxyBean (CatalogTarget and Catalog respectively). The init-method of the CatalogTarget loads all the root categories from the database. These are represented by Category objects. These Category objects in turn only load the ID of their parent and child Categories. (Obviously at the root, it's only children). To actually return the Category object with a given ID, the Category objects use a reference to the Catalog to look it up. The problem here is that the Catalog Service object (which is actually the TransactionProxyFactoryBean) isn't initialized yet because it's waiting on the CatalogTarget to finish initializing. A reference to the Catalog Service can not be given to the Category objects and I get a nice stacktrace alerting me to my circular dependency. The reason it wasn't circular before was because the TransactionFactoryProxyBean targeted the DAO object which was then given to the Catalog Service object and by then the Catalog Service was ready to go during it's init-method.

    I'm trying to find a sane way out of this without changing the behavior of the Category objects. What I come up with is making a new bean whose only job is take a reference of Catalog (the one created from the TransactionFactoryProxyBean) and call the init-method from there instead of defining it on the bean definition of the Catalog Service target bean. Seems like a bit of a hack though. Is there a cleaner solution?

    Thanks,
    Patrick

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

    Default

    At the end of the day, you've got a circular dependency, so introducing a third object is probably the cleanest way to handle this...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    46

    Default

    Well, I guess it is the best I can do for now. I've already created the new 3rd object and it's working well.

    Thanks for the input.

    Patrick

Similar Threads

  1. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  2. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  3. Debug exceptions using ContextSingletonBeanFactoryLocator
    By timothygordon32 in forum Container
    Replies: 2
    Last Post: Feb 21st, 2005, 11:19 AM
  4. setting a dependency on a factory result
    By fox9 in forum Container
    Replies: 3
    Last Post: Feb 18th, 2005, 05:23 AM
  5. Replies: 1
    Last Post: Jan 14th, 2005, 11:34 PM

Posting Permissions

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