package com.bjpowernode.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.bjpowernode.spring.Bean1;
import com.bjpowernode.spring.Bean2;
import com.bjpowernode.spring.Bean6;
import junit.framework.TestCase;
public class InjectionTest extends TestCase {
private BeanFactory factory;
/**
* TestCase的初始化方法
*/
@Override
protected void setUp() throws Exception {
// String[] configLocations = new String[]{"applicationContext.xml",
// "applicationContext-editor.xml"};
// factory = new ClassPathXmlApplicationContext(configLocations);
factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
}
/**
* TestCase的销毁方法
*/
@Override
protected void tearDown() throws Exception {
}
public void testInjection2() {
Bean2 bean2 = (Bean2)factory.getBean("bean2");
System.out.println("bean2.bean3.id=" + bean2.getBean3().getId());
System.out.println("bean2.bean3.name=" + bean2.getBean3().getName());
System.out.println("bean2.bean3.sex=" + bean2.getBean3().getSex());
System.out.println("bean2.bean4.id=" + bean2.getBean4().getId());
System.out.println("bean2.bean4.name=" + bean2.getBean4().getName());
System.out.println("bean2.bean4.sex=" + bean2.getBean4().getSex());
System.out.println("bean2.bean4.age=" + bean2.getBean4().getAge());
System.out.println("bean2.bean5.password=" + bean2.getBean5().getPassword());
}
}
3.Spring完成自动装配,两种方式:测试
最新推荐文章于 2024-09-30 07:15:00 发布