List of usage examples for org.springframework.context ApplicationContext getBeansOfType
<T> Map<String, T> getBeansOfType(@Nullable Class<T> type) throws BeansException;
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find data source bean.// w w w .j a v a2 s.c o m * * @param appCtx * the app ctx * @return the data source * @throws NoSuchBeanDefinitionException * the no such bean definition exception */ public static IMyWebDriver findMyWebDriver(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, IMyWebDriver> drivers = appCtx.getBeansOfType(IMyWebDriver.class); if (drivers.isEmpty()) { throw new NoSuchBeanDefinitionException(DataSource.class); } else { IMyWebDriver retDriver = drivers.values().iterator().next(); if (null == retDriver) { throw new NoSuchBeanDefinitionException(DataSource.class); } else { return retDriver; } } }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find test project bean.//from w ww.j av a 2 s.com * * @param appCtx * the app ctx * @return the test project * @throws NoSuchBeanDefinitionException * the no such bean definition exception */ public static TestProject findTestProjectBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, TestProject> testProjects = appCtx.getBeansOfType(TestProject.class); if (testProjects.isEmpty()) { throw new NoSuchBeanDefinitionException(TestProject.class); } else { TestProject testProject = testProjects.values().iterator().next(); if (null == testProject) { throw new NoSuchBeanDefinitionException(TestProject.class); } else { return testProject; } } }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find step data logger bean./*w w w .j ava2 s . c om*/ * * @param appCtx the app ctx * @return the step data logger * @throws NoSuchBeanDefinitionException the no such bean definition exception */ public static StepDataLogger findStepDataLoggerBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, StepDataLogger> loggers = appCtx.getBeansOfType(StepDataLogger.class); if (loggers.isEmpty()) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { StepDataLogger retVal = loggers.values().iterator().next(); if (null == retVal) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { return retVal; } } }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find db initializer./*from www .ja v a2 s . c om*/ * * @param appCtx * the app ctx * @return the test database initializer */ public static TestDatabaseInitializer findDBInitializer(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, TestDatabaseInitializer> dbInit = appCtx.getBeansOfType(TestDatabaseInitializer.class); if (dbInit.isEmpty()) { throw new NoSuchBeanDefinitionException(TestDatabaseInitializer.class); } else { TestDatabaseInitializer retVal = dbInit.values().iterator().next(); if (null == retVal) { throw new NoSuchBeanDefinitionException(TestDatabaseInitializer.class); } else { return retVal; } } }
From source file:org.zkoss.spring.security.SecurityUtil.java
private static void initializeIfRequired() { if (_applicationContext != null) { return;/*from w w w . java2 s . c om*/ } _applicationContext = SpringUtil.getApplicationContext(); Map map = new HashMap(); ApplicationContext context = _applicationContext; while (context != null) { map.putAll(context.getBeansOfType(AclService.class)); context = context.getParent(); } if (map.size() != 1) { throw new UiException( "Found incorrect number of AclService instances in application context - you must have only have one!"); } _aclService = (AclService) map.values().iterator().next(); map = _applicationContext.getBeansOfType(SidRetrievalStrategy.class); if (map.size() == 0) { _sidRetrievalStrategy = new SidRetrievalStrategyImpl(); } else if (map.size() == 1) { _sidRetrievalStrategy = (SidRetrievalStrategy) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of SidRetrievalStrategy instances in application " + "context - you must have only have one!"); } map = _applicationContext.getBeansOfType(ObjectIdentityRetrievalStrategy.class); if (map.size() == 0) { _objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl(); } else if (map.size() == 1) { _objectIdentityRetrievalStrategy = (ObjectIdentityRetrievalStrategy) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of ObjectIdentityRetrievalStrategy instances in " + "application context - you must have only have one!"); } map = _applicationContext.getBeansOfType(PermissionFactory.class); if (map.size() == 0) { permissionFactory = new DefaultPermissionFactory(); } else if (map.size() == 1) { permissionFactory = (PermissionFactory) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of PermissionFactory instances in " + "application context - you must have only have one!"); } }
From source file:org.apache.asyncweb.spring.HttpServiceLoader.java
public void setApplicationContext(ApplicationContext context) { Map<String, HttpService> services = context.getBeansOfType(HttpService.class); for (Iterator<Map.Entry<String, HttpService>> iter = services.entrySet().iterator(); iter.hasNext();) { Map.Entry<String, HttpService> entry = iter.next(); String serviceName = entry.getKey(); HttpService service = entry.getValue(); handler.addHttpService(serviceName, service); }//w ww.ja va2 s. c o m }
From source file:sample.data.mock.MockConversionService.java
public void setApplicationContext(ApplicationContext context) { this.repositories = context.getBeansOfType(CrudRepository.class).values(); this.conversionService.addConverter(this); }
From source file:com.github.lynxdb.server.core.Aggregators.java
@Autowired public Aggregators(ApplicationContext _context) { Map<String, Aggregator> tmp = new HashMap<>(); _context.getBeansOfType(Aggregator.class).forEach((String t, Aggregator u) -> { tmp.put(u.getName(), u);//from ww w. j a va 2 s .c o m }); this.aggregators = Collections.unmodifiableMap(tmp); }
From source file:org.mule.ibeans.spring.IBeanInjectorsBeanPostProcessor.java
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Map beans = applicationContext.getBeansOfType(IBeansContext.class); IBeansContext ctx = (IBeansContext) beans.values().iterator().next(); muleContext = (MuleContext) ctx.getConfig().get(MuleContext.class.getName()); injectDelegate = new InjectAnnotationProcessor(muleContext); applicationAnnotationsProcessor = new AnnotatedServiceObjectProcessor(muleContext); }
From source file:com.compomics.cell_coord.factory.TrackFileParserFactory.java
/** * Private constructor// ww w. ja v a 2 s.c o m */ private TrackFileParserFactory() { ApplicationContext context = ApplicationContextProvider.getInstance().getApplicationContext(); parsers = context.getBeansOfType(TrackFileParser.class); }