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
Kengkaj Sathianpantarit wrote:I think Eduardo is right.
We shouldn't use getBean() directly, we should use DI instead.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
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
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
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Nathan Pruett wrote:Gerardo,
I'd use bean "something" elsewhere in my code the same way I used bean "aDependency" in "something"....
Eduardo Bueno wrote:
Actually, you didn't show how you would use the bean "something". I think Gerardo was right; anywhere in your application you will have to call a Spring function to instantiate a bean for you, which will cause all subsequent beans to also be injected. Please correct (and clarify) me if I am wrong.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Eduardo Bueno wrote:
So it means SomewhereElse should be injected by something (not the attribute, jumbling names) other than you doing new SomewhereElse();.
Does a Servlet (which is injected by the container) solves the problem? I tried in an example here but got no success.
Eduardo Bueno wrote:Ok, but still there's no clear explanation on how to use attribute 'something' from SomewhereElse class.
If I create another class:
So it means SomewhereElse should be injected by something (not the attribute, jumbling names) other than you doing new SomewhereElse();.
Eduardo Bueno wrote:
Does a Servlet (which is injected by the container) solves the problem? I tried in an example here but got no success.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Gerardo Tasistro wrote:Nathan we are quite aware that the classes inside the XML are not aware of the usage of Spring. "something" and "somewhere" are not calling getBean to obtain "aDependency" and "something" respectively. Spring is handling the wiring. But at some point you will need to use getBean or some other method of obtaining "somewhere". You still haven't shown us how you make use of "somewhere". Up till now it remains an entity inside the Spring application context. In my experience this is achieved either by calling getBean at some point in your application (preferably something like a factory pattern so you can decouple Spring) or by using some class which is inherently aware of the Spring context (for example a Spring MVC controller). In this case, the classes are not aware they're being used by a Spring MVC controller. You don't even need to do anything special to them to wire them through Spring. This is were the "nonintrusiveness" of Spring resides. But I wouldn't go so far as to say "you don't have to explicitly call Spring functions in your code."
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|