我正在使用下面的代码进行我的Spring maven应用程序的JUnit测试
private static BeanFactory servicefactory = null;
private static BookingProcessService bookingProcessService;
@BeforeClass
public static void setUpBeforeClass() throws Exception{
try{
String[] configFiles = {"applicationcontext-Service.xml","applicationcontext-Hibernate.xml","applicationContext-dao.xml"};
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(configFiles);
servicefactory = (BeanFactory) appContext;
bookingProcessService = (BookingProcessService) servicefactory.getBean("bookingProcessService");
}catch (Exception e){
e.printStackTrace();
}
}
在使用maven构建我的项目时,我遇到了一些错误。名为 bookingProcessBusiness 的bean未创建可能是因为spring configuartion文件没有正确加载。
有人可以帮帮我吗?
答案 0 :(得分:4)
请提供您获得的确切例外
是的,您吞咽而不是进一步抛出让JUnit知道某事的例外是错误的。不要这样做:
}catch (Exception e){
e.printStackTrace();
}
为什么不使用内置Spring support for integration testing?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"applicationcontext-Service.xml","applicationcontext-Hibernate.xml","applicationContext-dao.xml"})
public class BookingProcessServiceTest {
@Autowired
private BookingProcessService bookingProcessService;
}
没有胶水代码,没有static
s。