getHibernateTemplate() 一直报NullPointerException 错误

时间:2022-06-22 10:31:54

原来是调用方法有误正确调用方法:

 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
com.springmvc.hibernate.NewsDAO newsdao=(NewsDAO) ctx.getBean("NewsDAO");
com.springmvc.hibernate.News news=new com.springmvc.hibernate.News();
news.setId();
news.setTitle("");
news.setContents("");
news.setUpdatetime( new Timestamp(System.currentTimeMillis()));
newsdao.save(news);

错误调用方法:

com.springmvc.hibernate.NewsDAO newsdao =new com.springmvc.hibernate.NewsDAO ();