Skip to main content

Posts

Showing posts from December, 2010

Using Spring Bean from Servlet

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.