List of usage examples for org.springframework.beans.factory BeanFactory getBean
<T> T getBean(Class<T> requiredType, Object... args) throws BeansException;
From source file:net.chrisrichardson.foodToGo.ejb3.jndi.TheBeanFactory.java
public static Object getBean(String selector, String factoryKey, String name, Class type) { if (selector == null) selector = "configurations/default-spring-context.xml"; if (factoryKey == null) factoryKey = "spring-context.xml"; BeanFactoryReference reference = ContextSingletonBeanFactoryLocator .getInstance(System.getProperty("spring.configuration", selector)).useBeanFactory(factoryKey); BeanFactory beanFactory = reference.getFactory(); return beanFactory.getBean(name, type); }
From source file:de.blizzy.documentr.markdown.macro.MessageSourceMacroDescriptor.java
static MessageSourceMacroDescriptor create(String macroName, BeanFactory beanFactory) { return (MessageSourceMacroDescriptor) beanFactory.getBean(ID, macroName); }
From source file:lodsve.core.condition.ConditionEvaluationReport.java
private static void locateParent(BeanFactory beanFactory, ConditionEvaluationReport report) { if (beanFactory != null && report.parent == null && beanFactory.containsBean(BEAN_NAME)) { report.parent = beanFactory.getBean(BEAN_NAME, ConditionEvaluationReport.class); }/*from ww w .ja v a2s . c om*/ }
From source file:com.taobao.itest.listener.TransactionalListener.java
/** * Obtain a PlatformTransactionManager from the given BeanFactory, matching * the given qualifier./* ww w.j a va 2 s .c o m*/ * * @param beanFactory * the BeanFactory to get the PlatformTransactionManager bean * from * @param qualifier * the qualifier for selecting between multiple * PlatformTransactionManager matches * @return the chosen PlatformTransactionManager (never <code>null</code>) * @throws IllegalStateException * if no matching PlatformTransactionManager bean found */ @SuppressWarnings("unused") private static PlatformTransactionManager getTransactionManager(BeanFactory beanFactory, String qualifier) { if (beanFactory instanceof ConfigurableListableBeanFactory) { // Full qualifier matching supported. return getTransactionManager((ConfigurableListableBeanFactory) beanFactory, qualifier); } else if (beanFactory.containsBean(qualifier)) { // Fallback: PlatformTransactionManager at least found by bean name. return (PlatformTransactionManager) beanFactory.getBean(qualifier, PlatformTransactionManager.class); } else { throw new IllegalStateException("No matching PlatformTransactionManager bean found for bean name '" + qualifier + "'! (Note: Qualifier matching not supported because given BeanFactory does not " + "implement ConfigurableListableBeanFactory.)"); } }
From source file:acromusashi.stream.helper.SpringContextHelper.java
/** * ????????????// ww w . ja v a 2s . c o m * * @param componentName ???? * @param componentType ?? * * @param <T> ?????? * @return ??? */ public <T> T getComponent(String componentName, Class<T> componentType) { BeanFactory factory = getBeanFactory(); T component = factory.getBean(componentName, componentType); return component; }
From source file:org.ops4j.gaderian.utilities.impl.SpringLookupFactory.java
public Object createCoreServiceImplementation(ServiceImplementationFactoryParameters factoryParameters) { SpringBeanParameter p = (SpringBeanParameter) factoryParameters.getFirstParameter(); String beanName = p.getName(); BeanFactory f = p.getBeanFactory(); if (f == null) f = _defaultBeanFactory;//from w ww .j a v a 2 s .c om return f.getBean(beanName, factoryParameters.getServiceInterface()); }
From source file:com.arondor.common.reflection.gwt.server.DefaultGWTReflectionService.java
public DefaultGWTReflectionService() { DefaultReflectionService defaultReflectionService = (DefaultReflectionService) getReflectionService(); BeanFactory beanFactory = new ClassPathXmlApplicationContext("reflection-config.xml"); AccessibleClassProvider accessibleClassProvider = beanFactory.getBean("accessibleClassProvider", AccessibleClassProvider.class); accessibleClassProvider.provideClasses(defaultReflectionService.getAccessibleClassCatalog()); }
From source file:edu.wisc.my.portlets.dmp.tools.XmlMenuPublisher.java
/** * Publishes all the menus in the XML specified by the URL. * //from w w w.j av a 2s . co m * @param xmlSourceUrl URL to the menu XML. */ public void publishMenus(URL xmlSourceUrl) { LOG.info("Publishing menus from: " + xmlSourceUrl); try { //The XMLReader will read in the XML document final XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); try { reader.setFeature("http://apache.org/xml/features/validation/dynamic", true); reader.setFeature("http://apache.org/xml/features/validation/schema", true); final URL menuSchema = this.getClass().getResource("/menu.xsd"); if (menuSchema == null) { throw new MissingResourceException("Could not load menu schema. '/menu.xsd'", this.getClass().getName(), "/menu.xsd"); } reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", menuSchema.toString()); } catch (SAXNotRecognizedException snre) { LOG.warn("Could not enable XSD validation", snre); } catch (SAXNotSupportedException xnse) { LOG.warn("Could not enable XSD validation", xnse); } final MenuItemGeneratingHandler handler = new MenuItemGeneratingHandler(); reader.setContentHandler(handler); reader.parse(new InputSource(xmlSourceUrl.openStream())); final Map menus = handler.getMenus(); final BeanFactory factory = this.getFactory(); final MenuDao dao = (MenuDao) factory.getBean("menuDao", MenuDao.class); for (final Iterator nameItr = menus.entrySet().iterator(); nameItr.hasNext();) { final Map.Entry entry = (Map.Entry) nameItr.next(); final String menuName = (String) entry.getKey(); final MenuItem rootItem = (MenuItem) entry.getValue(); LOG.info("Publishing menu='" + menuName + "' item='" + rootItem + "'"); dao.storeMenu(menuName, rootItem); } LOG.info("Published menus from: " + xmlSourceUrl); } catch (IOException ioe) { LOG.error("Error publishing menus", ioe); } catch (SAXException saxe) { LOG.error("Error publishing menus", saxe); } }
From source file:com.alacoder.lion.rpc.springsupport.BasicServiceConfigBean.java
public List<RegistryConfig> extractRegistries(String registries, BeanFactory beanFactory) { if (registries != null && registries.length() > 0) { if (!registries.contains(",")) { RegistryConfig registryConfig = beanFactory.getBean(registries, RegistryConfig.class); return Collections.singletonList(registryConfig); } else {//from w w w . j av a 2s . c o m List<RegistryConfig> registryConfigList = SpringBeanUtil.getMultiBeans(beanFactory, registries, SpringBeanUtil.COMMA_SPLIT_PATTERN, RegistryConfig.class); return registryConfigList; } } else { return null; } }
From source file:org.brekka.stillingar.spring.bpp.BeanReferenceResolver.java
/** * Perform the lookup of the bean via {@link BeanFactory#getBean(...)} *///from www .j a va 2 s.c o m @Override public Object getValue() { BeanFactory beanFactory = beanFactoryRef.get(); if (beanFactory == null) { // No longer available, just return null return null; } Object value; if (qualifier != null) { value = beanFactory.getBean(qualifier.value(), type); } else { value = beanFactory.getBean(type); } return value; }