5.Spring bean常见属性的注入:测试

来源:互联网 发布:angular js 跨域访问 编辑:程序博客网 时间:2024/05/22 09:38
package com.bjpowernode.test;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.bjpowernode.spring.Bean1;import junit.framework.TestCase;public class InjectionTest extends TestCase {private BeanFactory factory;/** * TestCase的初始化方法 */@Overrideprotected void setUp() throws Exception {// String[] configLocations = new String[]{"applicationContext.xml",// "applicationContext-editor.xml"};// factory = new ClassPathXmlApplicationContext(configLocations);factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");}/** * TestCase的销毁方法 */@Overrideprotected void tearDown() throws Exception {}public void testInjection1() {Bean1 bean1 = (Bean1) factory.getBean("bean1");System.out.println("bean1.strValue=" + bean1.getStrValue());System.out.println("bean1.intValue=" + bean1.getIntValue());System.out.println("bean1.listValue=" + bean1.getListValue());System.out.println("bean1.setValue=" + bean1.getSetValue());System.out.println("bean1.arrayValue=" + bean1.getArrayValue());System.out.println("bean1.mapValue=" + bean1.getMapValue());System.out.println("bean1.dateValue=" + bean1.getDateValue());}}

原创粉丝点击