Inject the spring environment into the servlet

Source: Internet
Author: User

  
 
  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. }
You just need to integrate this servlet.

Null

Inject the spring environment into the servlet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.