public class ServletProxy extends GenericServlet
{
private Servlet proxy;
public void init() throws ServletException
{
String servletName = getServletConfig().getServletName();
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
this.proxy = (Servlet) wac.getBean(servletName);
}
@Override
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
this.proxy.service(request, response);
}
}
<servlet> <servlet-name>userAction</servlet-name> <servlet-class>ServletProxy</servlet-class> </servlet> <servlet-mapping> <servlet-name>userAction</servlet-name> <url-pattern>/user</url-pattern> </servlet-mapping>
<bean id="userService" class="service.impl.UserServiceImpl"></bean> <bean id="userAction" class="action.userAction"> <property name="userService" ref="userService"></property> </bean>