public class Run {
public static void main(String[] args) {
String fileName = "./src/ioc/common/config/config.xml";
ApplicationContext ac = new FileSystemXmlApplicationContext
(fileName);
// 取得一个实例
UserBean user = (UserBean) ac.getBean("userBean");
System.out.println(user);
}
}
//end of Run.java
框架:有固定流程的代码集合,代码中的流程能被反复重用
备注:
1.如果构造器(方法)中没有写任何代码又会如何?
答:将会输出 null-null,Spring不关心构造器实现何种功能,只去调用执行;
2.如果没有这个构造器会如何?
答:将会使Spring找不到该构造器而产生异常
Exception in thread "main"
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userBean' defined in file
[/home/tarena/corejava/JSP/SpringPrj/./src/ioc/common/config/config.xml]:
2 constructor arguments specified but no matching constructor found in bean 'userBean' (hint: specify index and/or type arguments for simple parameters to avoid type ambiguities)