自定义(继承自 javax.servlet.http.HttpServlet)的 Servlet 如何像 Struts1/2 中那样调用 Spring 容器的 service 呢?
如同 Struts1/2 的配置一样,Spring 在 web.xml 中的配置及其 application*.xml 配置不变:
web.xml 中:
applicationContext-service.xml 中:
如同一般的 Servlet 的配置一样,Servlet 在 web.xml 中的配置不变:
如同一般的 Struts1/2 的 action 一样注入 service:
在 Servlet 中如同一般的 Struts1/2 的 action 一样调用 service:
唯一需要修改的是 Servlet 的 init 方法: