List of usage examples for org.springframework.beans.factory BeanFactoryUtils beanOfTypeIncludingAncestors
public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException
From source file:ru.histone.spring.mvc.HistoneView.java
private Histone autodetectHistone() throws BeansException { try {/*w ww. j av a 2 s. c o m*/ HistoneConfig histoneConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(), HistoneConfig.class, true, false); return histoneConfig.getHistone(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single HistoneConfig bean in this web application context " + "(may be inherited): HistoneConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } }
From source file:org.wp.spring.php.view.PHPView.java
@Override protected void initServletContext(ServletContext servletContext) { checkServletAPIVersion(servletContext); if (_context == null) { _context = BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(), PhpContext.class, true, false);/* w ww . j a v a2 s .c om*/ } // _context.getContext().setPwd(new FilePath(servletContext.getRealPath("/"))); _context.getContext().init(); _context.getContext().setServletContext(servletContext); }
From source file:org.openmrs.contrib.metadatarepository.webapp.taglib.LabelTag.java
/** * Get the validator resources from a ValidatorFactory defined in the * web application context or one of its parent contexts. * The bean is resolved by type (org.springframework.validation.commons.ValidatorFactory). * * @return ValidatorResources from a ValidatorFactory. *//*www. j a va 2s.c o m*/ private ValidatorResources getValidatorResources() { // look in servlet beans definition (i.e. action-servlet.xml) 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) { // look in main application context (i.e. applicationContext.xml) ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext()); factory = (ValidatorFactory) BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); } return factory.getValidatorResources(); }
From source file:org.sakaiproject.hierarchy.tool.vm.spring.VelocityView.java
/** * Autodetect a VelocityEngine via the ApplicationContext. * Called if no explicit VelocityEngine has been specified. * @return the VelocityEngine to use for VelocityViews * @throws BeansException if no VelocityEngine could be found * @see #getApplicationContext/* w ww .j a va 2 s . c o m*/ * @see #setVelocityEngine */ protected VelocityEngine autodetectVelocityEngine() throws BeansException { try { VelocityConfig velocityConfig = (VelocityConfig) BeanFactoryUtils .beanOfTypeIncludingAncestors(getApplicationContext(), VelocityConfig.class, true, false); return velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application context " + "(may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } }
From source file:alpha.portal.webapp.taglib.LabelTag.java
/** * Get the validator resources from a ValidatorFactory defined in the web * application context or one of its parent contexts. The bean is resolved * by type (org.springframework.validation.commons.ValidatorFactory). * /*from w w w . jav a2 s .c o m*/ * @return ValidatorResources from a ValidatorFactory. */ private ValidatorResources getValidatorResources() { // look in servlet beans definition (i.e. action-servlet.xml) WebApplicationContext ctx = (WebApplicationContext) this.pageContext.getRequest() .getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); ValidatorFactory factory = null; try { factory = BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); } catch (final NoSuchBeanDefinitionException e) { // look in main application context (i.e. applicationContext.xml) ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.pageContext.getServletContext()); factory = BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); } return factory.getValidatorResources(); }
From source file:net.alpha.velocity.spring.web.VelocityView.java
/** * Autodetect a VelocityEngine via the ApplicationContext. * Called if no explicit VelocityEngine has been specified. * * @return the VelocityEngine to use for VelocityViews * @throws BeansException if no VelocityEngine could be found * @see #getApplicationContext/*from ww w . j a v a 2 s . c o m*/ * @see #setVelocityEngine */ protected VelocityEngine autodetectVelocityEngine() throws BeansException { try { VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(), VelocityConfig.class, true, false); return velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application context " + "(may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } }
From source file:org.springmodules.validation.commons.taglib.JavascriptValidatorTag.java
/** * Get the validator resources from a ValidatorFactory defined in the * web application context or one of its parent contexts. * The bean is resolved by type (org.springmodules.commons.validator.ValidatorFactory). * * @return ValidatorResources from a ValidatorFactory *//*from w ww . j a va2 s .c o m*/ private ValidatorResources getValidatorResources() { WebApplicationContext ctx = (WebApplicationContext) pageContext.getRequest() .getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (ctx == null) { // look in main application context (i.e. applicationContext.xml) ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext()); } ValidatorFactory factory = (ValidatorFactory) BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx, ValidatorFactory.class, true, true); return factory.getValidatorResources(); }
From source file:org.theospi.portfolio.shared.control.XmlElementView.java
/** * Invoked on startup. Looks for a single VelocityConfig bean to * find the relevant VelocityEngine for this factory. *///from w w w.j a v a2 s.c om protected void initApplicationContext() throws BeansException { super.initApplicationContext(); if (this.velocityEngine == null) { try { VelocityEngineFactory velocityConfig = (VelocityEngineFactory) BeanFactoryUtils .beanOfTypeIncludingAncestors(getApplicationContext(), VelocityEngineFactory.class, true, true); this.velocityEngine = velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application " + "context (may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } } try { // check that we can get the template, even if we might subsequently get it again this.template = getVelocityTemplate(); } catch (ResourceNotFoundException ex) { throw new ApplicationContextException("Cannot find Velocity template for URL [" + getBaseUrl() + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new ApplicationContextException("Cannot load Velocity template for URL [" + getBaseUrl() + "]", ex); } }