天天看點

【Spring】【STS插件】【Junit支援】

用于在編寫XML的時候提示輸出

1. 手動安裝插件:

springsource-tool-suite

根據Eclipse的版本選擇合适的安裝包

【Spring】【STS插件】【Junit支援】

下載下傳完成後

安裝

【Spring】【STS插件】【Junit支援】
【Spring】【STS插件】【Junit支援】
【Spring】【STS插件】【Junit支援】

勾選4個IDE,取消自動更新

【Spring】【STS插件】【Junit支援】

安裝後重新開機eclipse,然後xml檔案上右鍵Open With可以看到有Spring Config editor的提示

2. 使用Spring安裝好的插件包:(新手推薦方式!!)

Spring Tool Suite™

根據不同的eclipse版本下載下傳即可

【Spring】【STS插件】【Junit支援】

STS安裝報錯一般是因為GEF,報錯資訊如下

【Spring】【STS插件】【Junit支援】

解決方案:

安裝GEF

網址:GEF

參考連結:Stack Overflow

【Spring】【STS插件】【Junit支援】

從GEF官網下載下傳一個GEF包,安裝所有

然後再安裝STS插件即可

Spring的Junit支援

不需要每次自己手動建立容器對象

最小包導入要求:

【Spring】【STS插件】【Junit支援】

其中test包是支援Junit的

代碼寫法:

比如Demo.java

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

//幫我們建立容器
@RunWith(SpringJUnit4ClassRunner.class)
//指定建立容器時使用哪個配置檔案
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo {
	//将名為user的對象注入到u變量中
	@Resource(name="user")
	private User u;
	
	@Test
	public void fun1(){
		
		System.out.println(u);
		
	}
	
	@Test
	public void fun2(){
		
		System.out.println(u);
		
	}
	
	@Test
	public void fun3(){
		
		System.out.println(u);
		
	}
}