Servlet获取Spring注解

public class UploadSevlet extends HttpServlet {
	private static final long serialVersionUID = 4738756696822806899L;


	private UserService userService;
	
	public void init(ServletConfig config) {
	    //spring获取注解
		WebApplicationContext wac = WebApplicationContextUtils 
                .getRequiredWebApplicationContext(config.getServletContext()); 
		userService = (UserService) wac.getBean("userService"); 
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


你可能感兴趣的:(Servlet获取Spring注解)