views:

18

answers:

1

Say I have a database layer, with DTO's for each table, and a factory that returns the DTO's for each table.

As long as I build to interfaces, I can re-implement the db layer and then just change my app-config.xml to use another implementation.

Now, is it possible for me to have this new implementation in another .jar file?

The goal is to allow for someone else to run this spring mvc application, drop their own implementation and change the app-config.xml file so that it now uses their library to re-implement a module.

Is this possible? How exactly do I go about this?

A: 

Is this possible?

Yes.

How exactly do I go about this?

Well the straight-forward approach would be to expose a setter for the DTOFactory instance in some bean that you have previously declared in your "app-config.xml" file. Then instantiate and inject the required DTOFactory bean via the corresponding property. To use an alternative factory, just change the classname in the bean.

The approach above assumes that your application currently use a shared instance of the (existing) DTOFactory class.

Stephen C
Yes wiring it up I think is what spring will do, so I just drop the .jar and it should work? what do you mean by 'shared instance'
Blankman
1) Yes. 2) What I mean is that if you have lots of instances of the factory object in your application, then you may need to wire them individually.
Stephen C