设为首页 加入收藏

TOP

Servlet 调用 Spring 容器的 service
2014-11-24 12:13:47 来源: 作者: 【 】 浏览:1
Tags:Servlet 调用 Spring 容器 service

自定义(继承自 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 方法:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C#多线程通信之委托(事件) 下一篇使用 Spring 容器管理 Servlet

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)