Ok, simple scenerio.. object A & B get created but they also need a reference to each other. Obviously, this creates a circular reference issue and I understand it. I'm trying to find a way around it so I don't have to change the coding which is still used by legacy systems. I'd like to avoid that if possible but it's an option.
Anyway, maybe a bit more background info might help.
Right now, I have a bean definition for object A which is a connector object that provides communication facilities to our backend system. Once instantiated, it will read in a xml config file and start creating all these objects it needs such as pools, pool managers, pool monitors, etc. These are objects B. Some of these, such as the monitors, require a reference back to the connector (object a) so that they may send message/transaction to the backend system to see if it's alive. If it doesn't reply within N seconds, it considers it not available... similar to a ping. So the way it's setup works great.
The problem, and reason why I'm moving this config file to spring bean xml definitions, is that we have 2 or 3 versions of this config file for each environment we deploy to since the ip, user id, passwords, etc changes. It makes for a deployment nightmare! And this nightmare isn't restricted to only this connector, it affects other beans we have.
The solution I proposed was to create a enhanced Spring PropertyPlaceholderConfigurer class that could retrieve bean property values from a database. So now, whenever I have a bean whose property need to be configurable by environment, I create a row in our database CONFIG table and give the property the value of ${XXX} where XXX is the the config code/id entered in the database. Works like a charm.
So, I'm now trying to do the same for the connector config file.... moving it to spring bean xml definitions. But I can't seem to find a way around this circular reference problem.
The only idea I've come up with (and I don't really like the approach) is to have an init() method to be invoked by supplying the bean's "init-method" attribute. The init() would call the setXXX() on the monitor once it's been initialized.
I REALLY hope someone can propose a solution or at least give me some ideas that will nudge me in the right direction.
Thanks!
Eric A. Gravel


Reply With Quote
