第一種:直接配置javabean文件
bean.xml
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml"});
personDao pe=(personDao)ctx.getBean("persondao");//通過配置javabean
}
bean.xml
springtest.java
personDao pe=(personDao)ctx.getBean("productCreator");
pe.test();
@note:紅色部分必須使用static關鍵字定義
3.xml配置+factory類,使用實例工廠方法實例化
bean.xml
新聞熱點
疑難解答