SpringMVC项目中偶尔用到servlet,如何在servlet中注入service笔记
来源:互联网 发布:淘宝网店怎么改价格 编辑:程序博客网 时间:2024/05/16 07:41
仅此做个笔记,防止注入时而成功时而失败的问题。
package com.zhy.spdb.sso;import java.io.IOException;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.context.support.SpringBeanAutowiringSupport;import com.zhy.spdb.sso.service.IUserService;public class LoginServlet extends HttpServlet{ private static final long serialVersionUID = -5205556322881482237L; @Autowired private IUserService userService; public void init(ServletConfig config) throws ServletException { //在servlet中注入service super.init(config); SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ String username = request.getParameter("username"); String password = request.getParameter("password"); String service = request.getParameter("service"); }}
核心代码
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
阅读全文
0 0
- SpringMVC项目中偶尔用到servlet,如何在servlet中注入service笔记
- 如何使用springmvc框架在普通的servlet注入service
- 在servlet注入service
- SpringMVC容器中Servlet如何调用service层接口
- SpringMVC容器中Servlet如何调用service层接口
- 在SpringMVC+mybatis框架中,servlet调用的service注解
- Servlet中使用Spring注入Service层
- 如何在Spring中注入servlet配置组件?
- 在servlet中如何使用被Spring管理的service
- servlet 中bean注入
- Servlet中Service方法
- servlet中service()方法
- Servlet中service()方法
- servlet 中注入 service 对象; 无需set 方法;
- 如何用Spring将Service注入到Servlet中
- 用Spring将Service注入到Servlet中
- 如何使用spring将service层注入到servlet中去(how to use Spring to inject ur service layer into the servlet )
- 如何使用spring将service层注入到servlet中去(how to use Spring to inject ur service layer into the servlet )
- 使用eclipse的Maven构建Web项目
- 解决Spark导入jblas包提示不存在的问题
- Gitlab利用Webhook实现Push代码后的jenkins自动构建
- 1.8
- jsp url 参数加密传送的终极解决方案
- SpringMVC项目中偶尔用到servlet,如何在servlet中注入service笔记
- 一步一步理解线段树
- monkey小用
- 阿里巴巴java开发手册学习记录
- android源码阅读--线程间通信Handler消息机制
- Pycharm 操作快捷键
- Struts2入门
- django基础学习心得
- jQuery.extend 函数详解