When your application server starts, Spring will do the instantiation for you. And will also "inject" the object in your class.
So, in order for the injection to happen, you will either have to write a setter method (which Spring will call once the object is instantiated)
public class MyClass{
private MyObject myObject;
public void setMyObject(MyObject _myObject){ //Spring will call this method
this.myObject = _myObject;
}
}
or you can have a constructor based injection
public class MyClass{
private MyObject myObject;
public MyClass(MyObject _myObject){ //Spring will call this constructor
this.myObject = _myObject
}
}
EDIT:
Thanks for pointing that out Peter D
In your XML config file you will have to do something like:
<bean name="myObject" class="mypackage.MyObject"/>
<bean name="myClass" class="mypackage.MyClass">
<property name="myObject" ref="myObject"/>
</bean>
Hope this helps!