1
<bean id="a" class="com.ioc.A" factory-method="getInstance"> <property name="b" ref="b" /> <property name="c" ref="c" /> </bean>
2
package com.ioc; public class A { B b; C c; public A() { } public A(String title) { System.out.println("i am single"); } public B getB() { return b; } public void setB(B b) { this.b = b; } public C getC() { return c; } public void setC(C c) { this.c = c; } @Override public String toString() { return "A [b=" + b + ", c=" + c + "]"; } public static A a = null; public static A getInstance() { if(a == null) { a = new A("hello"); } return a; } }