Reputation: 21310
I am using the below piece of code for JUnit test of my Spring maven application
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();
}
}
While building my project using maven, I am getting some errors.The bean named bookingProcessBusiness is not creating may be because the spring configuartion files are not properly loaded.
Can somebody please help me?
Upvotes: 0
Views: 96
Reputation: 340708
Please provide exact exception you are getting
Yes, the exception that you are swallowing instead of throwing further and letting JUnit know something is wrong. Don't do this:
}catch (Exception e){
e.printStackTrace();
}
Why won't you use built-in 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;
}
No glue code, no static
s.
Upvotes: 4