Hi all,
I am currently evaluating Spring and its potential benefits for J2EE application development here at INFOSYS in Bangalore.
We currently have one application that uses a component to determine and load the to-be-used service implementation for a service (depending on a RUNTIME parameter) and run the service with this implementation then in the next step.
BASIC GOAL: I would like to replace this component, i.e. use Spring configuration to set-up runtime target selection for the service implementation depending on a runtime parameter.
--> This seems not to be feasible with Spring out of the box!?
--> Idea: is there maybe something like proxy bean (used as placeholder for concrete serviceImpl) where the target can be selected a runtime from a map/"directory of targets" and the map/"directory" could be set-up like this:
key [customer-type-individual] --> target [serviceImplCustomerIndividual] (bean-ref to existing spring bean definition)
key [customer-type-business] --> target [serviceImplCustomerBusiness] (bean-ref to existing spring bean definition)
...Detailed Example [if not clear what I mean yet]:
[BUSINESS GOAL]: determine credit rating for specific customer
[ACHIEVED WITH]: CreditRatingService component/bean (has a property 'serviceImpl' holding the to-be-used & customer type-specific serviceImpl to calculate the credit rating)
[PARAMETER (at RUNTIME!)]: type of customer (business|individual) as string
[ACTIONS]:
[1] load customer-specific implemenation into service.serviceImpl bean property
[2] execute calculation: service.doCalc (using the service.serviceImpl that has been loaded dynamically)
I would like to replace the repeated lookup code which is currrently in place and which in general uses java reflection api for the serviceImpl selection using Spring configuration concepts.... goal: select target serviceImpl bean that has already been defined in Spring config.
Problem: the biggest hurdle seems to be to select the component at RUNTIME (and not configuration time) depending on the RUNTIME parameter (customer type) [this simply seems not to be feasible in using available Spring configuration means.
I did try the following:
[1 - "ugly"] Use AOP beforeMethod advice on "service.doCalc(String customerType)" to load correct serviceImpl before "service.doCalc()" executes depending on parameter 'customerType'
[...finding 1] does not replace lookup-component but simply wraps it into AOP advice and therefore does not get rid of reflection use
[...finding 2] reflection use could only be replaced by hard-coded selection of the appropriate service implementation (inject appropriate serviceImpl MANUALLY into service from a set reference from a set of given bean-refs to serviceImpls available in advice)
[2] read through bean factory interface documentation (idea: implement new factory type)
[...finding] getObject() does not support to pass in a parameter upon which the concrete instance (implementing the serviceImpl interface) could be returned --> not usable for my goal
Thanks for any ideas on this!
Michael


Reply With Quote