ListableBeanFactory lbf = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); ValidatorFactory factory = (ValidatorFactory) BeanFactoryUtils .beanOfTypeIncludingAncestors(lbf, ValidatorFactory.class, true, true);
WebApplicationContext ctx = (WebApplicationContext) pageContext.getRequest() .getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); ValidatorFactory factory = null; try { factory = (ValidatorFactory) BeanFactoryUtils .beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); } catch (NoSuchBeanDefinitionException e) {  ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); factory = (ValidatorFactory) BeanFactoryUtils .beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); }
    private ValidatorResources getValidatorResources() {        ListableBeanFactory lbf = WebApplicationContextUtils            .getRequiredWebApplicationContext(pageContext.getServletContext());        ValidatorFactory factory = (ValidatorFactory) BeanFactoryUtils                .beanOfTypeIncludingAncestors(lbf, ValidatorFactory.class, true, true);        return factory.getValidatorResources();    }