日期:2014-05-19 浏览次数:20794 次
public class TestAction extends ActionSupport{ ...... WebApplicationContextUtils.getRequiredWebApplicationContext().getBean("testDao"); }
public class TestTag extends TagSupport{ public int doStartTag() throws JspException{ ...... WebApplicationContextUtils.getRequiredWebApplicationContext().getBean("testDao"); } }
public class XxxTag extends RequestContextAwareTag { //覆盖doStartTagInternal方法 protected int doStartTagInternal() throws Exception { this.getRequestContext().getWebApplicationContext().getBean("beanName"); } }
------解决方案--------------------
在标签中可以通过pageContext得到servletContext
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext()); XxxService service = (XxxService)ctx.getBean("beanName");