You could create Factory beans and inject that into your A class, then call a method on it to create the B.
Just a thought of the top of my head, sorry I didn't think too hard on it for too long.
The main point with Spring and dependency injection is for you not to call "new"
there are beans that you can create and in the configuration set a factory-method or an init-method that it will call.
Look at the FactoryBean interface too to see if that might help.
If not, and you come across a situation that can't be resolved, look closely at the design there is usually a problem there that causes the tough situation. That is my motto.
Yes I am porting my project over from jboos/ejb to tomcat/spring so need to do a lot of design reviews regardless i guess. thought maybe spring has some quick and easy fix so I don't have to work too hard...
Well there is a Spring class that you can have your EJBs extend that would give them access to the ApplicationContext, but it then couples your EJB to a Spring specific class.
Mark
zabet tyan
Ranch Hand
Joined: Jan 14, 2009
Posts: 32
posted
0
Well I am running away from EJBs. So don't want to keep any EJBs around. Anyways, I redesigned that section, but had to have one of my class implement BeanFactoryAware.
Hong Anderson
Ranch Hand
Joined: Jul 05, 2005
Posts: 1936
posted
0
What is the reason that you cannot use DI?
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
zabet tyan
Ranch Hand
Joined: Jan 14, 2009
Posts: 32
posted
0
There is a config file that contains some information. Depending on some value in config file, say x = 4, I have to create 4 B objects.
Right now I set object B to have prototype scope in spring config and use beanFactoryAware to get the B object. Object B depends on object C and needs spring to inject it.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: how to make spring aware of bean initialization