跪求大神帮忙,不胜感激

来源:2-1 IOC及Bean容器

quietwaltz

2015-03-25 00:04

源码都没法下载,那个BlockJUnit4ClassRunner报错不知道是什么原因,UnitTestBase是自己写的类吗?

写回答 关注

1回答

  • 好帮手慕珊
    2015-03-25 09:08:47

    UnitTestBase是自己写的类,代码如下

    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;

    }

    }


    }


    butche...

    aligado

    2015-11-13 15:31:44

    共 1 条回复 >

Spring入门篇

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

268786 学习 · 963 问题

查看课程

相似问题