i am creating a spring-mvc project in which i had used hibernate integration.In this i have 2 classes one is operationdao which is used to perform hibernate operation and other is my convtroller class.
Code of operationDao class:
public class OperationDao { Configuration cfg=null; public OperationDao() { // TODO Auto-generated constructor stub cfg=new Configuration(); cfg.configure("hibernate.cfg.xml"); } public String saveShop(shops s) { SessionFactory factory=cfg.buildSessionFactory(); Session session=factory.openSession(); org.hibernate.Transaction t=session.beginTransaction(); try { Query query=session.createQuery("from shops"); query.setCacheable(true); List<shops> list=query.list(); Iterator<shops> i=list.iterator(); while(i.hasNext()) { shops shps=i.next(); if(shps.getShops_string().equals(s.getShops_string())) { return "done-2"; } } session.save(s); t.commit(); return "done"+String.valueOf(s.getId()); } catch(Exception e) { t.rollback(); return "done-1"; } finally { session.close(); } } }
code in my Controller class:
public class EmpController { OperationDao dao; public EmpController() { // TODO Auto-generated constructor stub dao=new OperationDao(); } @RequestMapping("/saveShop") public void saveShop(@ModelAttribute("shop") shops shop,HttpServletResponse responce) { String i=dao.saveShop(shop); try { responce.getWriter().println(i); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
But when i am trying to run my project on server,it shows me following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'empController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: work.OperationDao work.EmpController.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [work.OperationDao]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
But when i am creating instance of OpertionDao class for testing purpose than it doesn't show any error.so why error is coming in creating bean. Please Help i a badly stuck. Thanks in Advance: