Dependency Lookup is when your class is responsible for getting its dependencies from some lookup factory, (this is similar to a JNDI lookup).
for example ClassA has a ClassB,
in ClassA you will have a code something like this
while a Dependency Injection is when your class is given a dependency by some factory or framework
example ClassA has a ClassB,
you can see in Dependency Injection that the framework was responsible for injecting the instance of ClassB.
SCJA, SCJP, SCJD, SCMAD, SCWCD, SCBCD, SCDJWS, SCEA, SOA, Spring Certified, OCP MySQL 5 Developer, PMP
Joined: Apr 07, 2009
sorry i have any question about "DI/IoC"..
if iam using Spring..
is it DI make our application to use Singleton Object?..
and how to i make a Singleton Object in spring?..
example i have class : com.leonardo.action.SomeAction
how to configure ir in a spring context to be an singleton object?..
and how to use it in my application?..
(Sorry my english isn't too good )
Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Yes and no, I like the code of MyClass, the next part is how you tell Spring there is the dependency between MyClass and the Hello class.
You can define another bean of type MyClass in your configuration and use a <property> tag in that <bean> tag that points or "ref"s references your "hello" bean. That is if you want it defined in the xml.
The other choice is to use Annotations. the @Autowired (Spring annotation) or the @Resource (JSR-250 annotation) does the trick. But to use annotations you have to put in the xml file that you are using annotations.
Now, if MyClass is not going to be a Spring Bean, then in MyClass you need to get a reference to the ApplicationContext object and call the getBean(String beanName) method.