Get Spring Annotated bean in Servlet's init method
I am using Spring 3.0 IOC & MVC with my application. And I came across a requirement that I want a spring bean to be accessed in my Servlet.
So, I made an entry in web.xml (for servlet), and in servlet's init() method I wrote a snippet to get Spring bean. To get Spring bean I'd used bellow snippet:
But by doing this, I am getting applicationContext value as null.
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
userService = applicationContext.getBean("userService", IUserService.class);
Servlet is configured as load-on-startup with order 2.
Spring beans are registered as annotated classes. (Controller, Model, Repository)
Can any one help me out?