package action;
import junit.framework.TestCase;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.HelloService;
public class HelloAction extends TestCase {
public void testContext() {
ApplicationContext context = new ClassPathXmlApplicationContext("hello.xml");
HelloService hello = (HelloService) context.getBean("helloService");
hello.print();
System.out.println("context");
}
public void testFactory() throws Exception {
ClassPathXmlApplicationContext resource = new ClassPathXmlApplicationContext("hello.xml");
BeanFactory factory = resource;
HelloService hello = (HelloService) factory.getBean("helloService");
hello.print();
System.out.println("factory");
}
}
注:将spring.jar、junit.jar、commons-logging.jar复制进WEB-INF/lib