来源:2-1 IOC及Bean容器

zplogo

2014-09-23 09:37

老师这个有点坑啊!!   import org.junit.Test; 这里导入全部隐藏看不到导入什么??

public class TestOneInterface extends UnitTestBase{} 这里的UnitTestBase 是老师自己定义的类吧   也没提供  根本找不到!!!



写回答 关注

2回答

  • 好帮手慕珊
    2015-03-25 09:01:59

    package com.imooc.test.base;


    import org.junit.After;

    import org.junit.Before;

    import org.springframework.beans.BeansException;

    import org.springframework.context.support.ClassPathXmlApplicationContext;

    import org.springframework.util.StringUtils;


    public class UnitTestBase {

    private ClassPathXmlApplicationContext context;

    private String springXmlpath;

    public UnitTestBase() {}

    public UnitTestBase(String springXmlpath) {

    this.springXmlpath = springXmlpath;

    }

    @Before

    public void before() {

    if (StringUtils.isEmpty(springXmlpath)) {

    springXmlpath = "classpath*:spring-*.xml";

    }

    try {

    context = new ClassPathXmlApplicationContext(springXmlpath.split("[,\\s]+"));

    context.start();

    } catch (BeansException e) {

    e.printStackTrace();

    }

    }

    @After

    public void after() {

    context.destroy();

    }

    @SuppressWarnings("unchecked")

    protected <T extends Object> T getBean(String beanId) {

    try {

    return (T)context.getBean(beanId);

    } catch (BeansException e) {

    e.printStackTrace();

    return null;

    }

    }

    protected <T extends Object> T getBean(Class<T> clazz) {

    try {

    return context.getBean(clazz);

    } catch (BeansException e) {

    e.printStackTrace();

    return null;

    }

    }


    }


  • 好帮手慕珊
    2014-09-23 10:34:20

     UnitTestBase是自定义的类,import内容如下:
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.BlockJUnit4ClassRunner;
    import com.imooc.ioc.interfaces.OneInterface;
    import com.imooc.test.base.UnitTestBase;


    quietw...

    请问UnitTestBase这个类具体是怎么定义的?

    2015-03-25 00:30:07

    共 1 条回复 >

Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268797 学习 · 1026 问题

查看课程

相似问题

回答 1

回答 1

回答 4

回答 2