課程
/后端開發(fā)
/Java
/Spring入門篇
class UnitTestBase 這個類就不能說一下嗎? 完整的代碼在哪里
2020-11-27
源自:Spring入門篇 3-1
正在回答
package com.imooc.test.base;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UnitTestBase {
String springXmlPath;
ClassPathXmlApplicationContext context;
public UnitTestBase() {}
public UnitTestBase(String springXmlPath){
this.springXmlPath = springXmlPath;
}
@Before
public void before(){
if("" == springXmlPath){
springXmlPath = "classpath*:spring-*.xml";
try{
context = new ClassPathXmlApplicationContext(springXmlPath.split("[,\\s]+"));
context.start();
}catch(Exception e){
e.printStackTrace();
@After
public void? after(){
context.destroy();
public <T extends Object > T getBean(String beanId){
return (T) context.getBean(beanId);
return null;
舉報
為您帶來IOC和AOP的基本概念及用法,為后續(xù)高級課程學習打下基礎(chǔ)
1 回答UnitTestBase
5 回答UnitTestbase
3 回答UnitTestBase
2 回答UnitTestBase
1 回答UnitTestBase類
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2020-11-29
package com.imooc.test.base;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UnitTestBase {
String springXmlPath;
ClassPathXmlApplicationContext context;
public UnitTestBase() {}
public UnitTestBase(String springXmlPath){
this.springXmlPath = springXmlPath;
}
@Before
public void before(){
if("" == springXmlPath){
springXmlPath = "classpath*:spring-*.xml";
}
try{
context = new ClassPathXmlApplicationContext(springXmlPath.split("[,\\s]+"));
context.start();
}catch(Exception e){
e.printStackTrace();
}
}
@After
public void? after(){
context.destroy();
}
public <T extends Object > T getBean(String beanId){
try{
return (T) context.getBean(beanId);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}