Junit获取Spring Bean对象

By | 2015年2月2日


package com.renyiwei.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.renyiwei.wydns.service.ProductService;

public class SpringBeanTest {

private static ApplicationContext ac;
static{
ac = new FileSystemXmlApplicationContext(testBean.class.getResource("/")+"applicationContext.xml");
}

@Test
public void test() throws Exception{
ProductService productService = (ProductService) ac.getBean("productService");
//
}

}

发表评论