Spring: factory-bean or what September 26, 2007
Posted by The Saint in Gyaan Korner, Technology.Tags: spring, Technology
trackback
There are two ways to defined factory beans in Spring.
1. Where you have a factory class or manager, which has static methods to return instances of various classes. For eg:
public class MyFactory {
public static ClassA getClassAInstance(){
….
return new ClassB();
}
public static ClassB getClassBInstance(){
….
return new ClassB();
}
}
the xml configuration would be:
2. The second approach is when you have a class which has non-static methods to return instances.
public class MyFactory {
public ClassA getClassAInstance(){
….
return new ClassB();
}
public ClassB getClassBInstance(){
….
return new ClassB();
}
}
In this case the xml configuration would slightly change to have another bean, which is then accessed in the other bean definitions.
HTH



Comments»
No comments yet — be the first.