码迷,mamicode.com
首页 > 编程语言 > 详细

在servlet中注入spring环境

时间:2017-08-16 15:28:32      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:injection   private   generate   imp   text   tle   cep   uid   get   

  1. import java.io.IOException;
  2. import javax.servlet.ServletConfig;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.springframework.web.context.support.SpringBeanAutowiringSupport;
  8. /**
  9. * Servlet implementation class AbstractServlet
  10. */
  11. public class AbstractServlet extends HttpServlet {
  12. private static final long serialVersionUID = 1L;
  13. /**
  14. * @see HttpServlet#HttpServlet()
  15. */
  16. public AbstractServlet() {
  17. super();
  18. // TODO Auto-generated constructor stub
  19. }
  20. public void init(ServletConfig config) throws ServletException {
  21. SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
  22. config.getServletContext());
  23. }
  24. /**
  25. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  26. * response)
  27. */
  28. protected void doGet(HttpServletRequest request,
  29. HttpServletResponse response) throws ServletException, IOException {
  30. }
  31. /**
  32. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  33. * response)
  34. */
  35. protected void doPost(HttpServletRequest request,
  36. HttpServletResponse response) throws ServletException, IOException {
  37. doGet(request, response);
  38. }
  39. }
只需要集成这个servlet即可。




在servlet中注入spring环境

标签:injection   private   generate   imp   text   tle   cep   uid   get   

原文地址:http://www.cnblogs.com/cyp1993/p/7373139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!