In order to use a Spring bean from Servlet use the following;
ServletContext context = getServletContext();
WebApplicationContext applicationContext =
WebApplicationContextUtils.getWebApplicationContext(context);
UserDao userdao = (UserDao) applicationContext.getBean("userDaoBeanName");
I ran into this issue when I tried using getHibernateTemplate() in servlet code. Unless you use the above code to get the bean, you will see a NullPointerException.
Comments