public class BaseTest {
private Logger logger = LogManager.getLogger(BaseTest.class);
public ApplicationContext ac ;
/**
* 初始化
*/
@Before
public void init(){
// 参数是配置文件
ac = new ClassPathXmlApplicationContext("applicationContext.xml");
logger.info("初始化:ac:{}",ac);
}
@Test
public void test(){
Dynasty dynasty = ac.getBean("dynasty", Dynasty.class);
System.out.println("BaseTest.test"+ dynasty);
}
@After
public void close(){
if(ac instanceof ClassPathXmlApplicationContext){
ClassPathXmlApplicationContext classPathXmlApplicationContext = (ClassPathXmlApplicationContext) ac;
classPathXmlApplicationContext.close();
}
}
}
配置文件在classpath路径的下面