I have a CustomerRelation class which has a method getInstance() and instance variable i.e
private CustomerCrudService relationshipService = null;
Brief about the getInstance method is
static public CustomerRelation getInstance() {
if (instance == null) {
instance = new customerRelation();//line1
}
return instance;//line2
}
Now i put the the debugger at line 1. After executing this line,i see instance is created containing relationshipService
object. My question is how dependency relationshipService got injected while creating the instance with new operator?
Though in MyProject-SpringConfig.xml i can see below configuration but still how the event , when we are creating the object
with new operator, is getting intercepted by spring core container? Is it because of spring customclassloader. If yes
where do we specify this?
<bean class="com.its.portfolio.relationship.CustomerRelation" scope="prototype">
<property name="relationshipService" ref="relationshipService" />
</bean>
Edit:- Here is the code of CustomerRelation
package com.its.relationship;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Configurable;
/**
* accessor for customerrelation meta data
*
*/
@Configurable
public class CustomerRelation implements ICustomerRelation {
static private CustomerRelation instance;
private ICustomerRelationshipCrudService relationshipService;
private CustomerRelation() {
}
static public ICustomerRelation getInstance() {
if (instance == null) {
instance = new CustomerRelation();
}
return instance;
}
}
It happens due to this bit of magic:
As you suspected, this uses a custom classloader (and load-time AOP weaving) to inject dependencies into your domain object on-the-fly.