spring實例化時
- public void test2() {
- ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
- //配置文件中的id屬性
- IHelloService service = (IHelloService) context.getBean("helloService");
- service.sayHello();
- }
可以將前面用子類來寫,並關閉
- public void test2() {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
- //配置文件中的id屬性
- IHelloService service = (IHelloService) context.getBean("helloService");
- service.sayHello();
- context.close();
- }