条件:使用框架为springMVC
import javax.servlet.http.HttpServlet;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class EsayServlet extends HttpServlet{
@Override
public void init(){
ApplicationContext ac= WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
ac.getBean("");
}
}