示例:
public class testService
{
public static EnterpriseinfoServiceImpl service;
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
System.out.println("加载配置文件……");
ApplicationContext context = new FileSystemXmlApplicationContext(new String[]{"src/applicationContext.xml"});
System.out.println("加载配置文件成功");
service = (EnterpriseinfoServiceImpl) context.getBean("enterpriseinfoService"); //enterpriseinfoService为applicationContext.xml配置文件中Service类对象id值
}
@Test
public void testSave()
{
try
{
Enterpriseinfo info = new Enterpriseinfo();
info.setEnglishabbreviation("Myenglishname");
info.setEnglishfullname("myenglishfullname");
info.setEnterpriseabbreviation("enterpriseabbreviation");
info.setEnterprisefullname("enterprisefullname");
info.setStockcode(12434);
info.setId(3);
service.save(info);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
注意:该测试方法测试后数据并不会自动回滚