getBean(String name)
引數說明:public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext( "appContext.xml"); //初始化容器物件 Object bean=context.getBean("dao"); //從容器中獲取dao物件 }
getBean(String name,Class requiredType)
引數說明:public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext( "appContext.xml"); //載入appContext.xml Object bean = context.getBean("time",Date.class); //獲取指定JavaBean物件 System.out.println("bean="+bean); }