实例:使用ClassFactory类创建一个Class类
public classClass{
int num;
public Class(intnum)
{
this.num=num;
}
}
public class ClassFactory{
public static Class getClass(int num)
{
System.out.println(num);
Returnnew Class(num);
}
}
applicationContext.xml
<bean id =”class” class=”ClassFactory”factory-method=”getClass”>
<constructor-arg value=”50”></constructor>
</bean>
Main方法:
public static void main(String[] arg)
{ ApplicationContextac=new ClassPathXMLApplicationContext(“applicationContext.xml”);
Class cl=ac.getBean(“class”,Class.class);//就可以得到我们的Class实例
}