在applicationContext.xml中定义数据层访问Bean:
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private UserDao userDao;
....
}
注入方法::在Servlet的init方法中增加以下代码:
public void init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
config.getServletContext());
}