Junit获取Spring Bean对象 - 全栈笔记

Junit获取Spring Bean对象

任亦伟 JAVA 2015-02-02 53 次浏览 没有评论

01
02
package com.renyiwei.test;
03
 
04
import org.junit.Test;
05
import org.springframework.context.ApplicationContext;
06
import org.springframework.context.support.FileSystemXmlApplicationContext;
07
 
08
import com.renyiwei.wydns.service.ProductService;
09
 
10
public class SpringBeanTest {
11
 
12
	private static ApplicationContext ac;
13
	static{
14
		ac = new FileSystemXmlApplicationContext(testBean.class.getResource("/")+"applicationContext.xml");
15
	}
16
 
17
	@Test
18
	public void test() throws Exception{
19
		ProductService productService = (ProductService) ac.getBean("productService");
20
		//
21
	}
22
 
23
}
24
 
25

发表评论

回顶部