org.springframework.transaction这个jar是管理事物的。
你都用
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
System.out.println("user saved!");
这个jar当然必须了。

解决方案 »

  1.   


    恩,谢谢,我引入这个包后又出错了,spring-orm-4.0.0.M1.jar包我也有引入
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAOImpl': Injection of resource dependencies failed; nested exception is java.lang.NoClassDefFoundError: [Lorg/hibernate/engine/FilterDefinition;
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
      

  2.   

    刚学,视频上的是,spring2.5,我用的4.0
      

  3.   

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAOImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [com.zhg.model.User] cannot be opened because it does not exist
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
      

  4.   

    sessionFactory也是注入进去的,这里看不到任何注入的信息
      

  5.   

    没注意看,注释配置了,但是sessionFactory不是这样配置就可以了。好像是要注入到HibernateTemplate的sessionFactory才算正确