Today I was asked by few of my colleagues to give a brief introduction about Spring Framework. I created this presentation and hope this is also able to help you. Comments are appreciated!
Here is some more code if you would like to understnad how can a class can be injected and used in other class.
Changes Made:
  1. Added: PrintMe.java
  2. Changed: HelloWorldImpl2.java, applicationContext.xml

Scenario: Use another class “PrintMe”  in class “HelloWorldImpl2” . ( Depenedency Injection of “PrintMe”  in “HelloWorldImpl2”)

  • In order to do this I have done the following changes in the applicationContext.xml
  • Defined the new class: <bean id=”printMe” class=”PrintMe”/>
  • Injected the class (in RED)

<bean id=”helloWorld” class=”HelloWorldImpl2″>

<property name=”print”>

<ref bean=”printMe” />

</property>

</bean>

  • Changed HelloWorldImpl2
    • Created an instance in of PrintMe

public PrintMe print = null;

  • Created a public getter and setter for print

public PrintMe getPrint() {

return print;

}

public void setPrint(PrintMe print) {

this.print = print;

}

  • Used the object

print.printIt();

DOWNLOAD FILES USED

Leave a Reply

Set your Twitter account name in your settings to use the TwitterBar Section.