package com.tomove.util; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class GetBeanServlet extends HttpServlet { private static WebApplicationContext context; // Initialize global variables public void init() throws ServletException { context = WebApplicationContextUtils.getWebApplicationContext(this .getServletContext()); } public static Object getBean(String id) { Object bean = context.getBean(id); return bean; } } web.xml <!-- GetBeanServlet --> <servlet> <servlet-name>GetBeanServlet</servlet-name> <servlet-class>com.tomove.util.GetBeanServlet</servlet-class> <load-on-startup>3</load-on-startup> </servlet>