- package com.wangcf;
- import org.junit.Test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class HelloTest {@Test public void testSayHello() {
- //创建Spring 容器
- ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
- //从容器中得到一个bean,也就是一个实例对象
- HelloWorld hello = (HelloWorld) context.getBean("helloworld");
- hello.sayHello();
- }
- }
来源: http://www.bubuko.com/infodetail-1864395.html