Java Code Examples for org.springframework.context.ApplicationContext#getBeansOfType()
The following examples show how to use
org.springframework.context.ApplicationContext#getBeansOfType() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ignite File: IgniteSpringHelperImpl.java License: Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> IgniteBiTuple<Collection<T>, ? extends GridSpringResourceContext> loadConfigurations( InputStream cfgStream, Class<T> cls, String... excludedProps) throws IgniteCheckedException { ApplicationContext springCtx = applicationContext(cfgStream, excludedProps); Map<String, T> cfgMap; try { cfgMap = springCtx.getBeansOfType(cls); } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate bean [type=" + cls + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new IgniteCheckedException("Failed to find configuration in: " + cfgStream); return F.t(cfgMap.values(), new GridSpringResourceContextImpl(springCtx)); }
Example 2
Source Project: oodt File: DistributedConfigurationManagerTest.java License: Apache License 2.0 | 6 votes |
@Before public void setUpTest() throws Exception { System.setProperty("org.apache.oodt.cas.cli.action.spring.config", "src/main/resources/cmd-line-actions.xml"); System.setProperty("org.apache.oodt.cas.cli.option.spring.config", "src/main/resources/cmd-line-options.xml"); ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), "-config", CONFIG_PUBLISHER_XML, "-a", "publish" }); ApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_PUBLISHER_XML); Map distributedConfigurationPublishers = applicationContext.getBeansOfType(DistributedConfigurationPublisher.class); publishers = new ArrayList<>(); configurationManagers = new HashMap<>(); for (Object bean : distributedConfigurationPublishers.values()) { DistributedConfigurationPublisher publisher = (DistributedConfigurationPublisher) bean; System.setProperty(OODT_PROJECT, publisher.getProject()); System.setProperty(publisher.getComponent().getHome(), "."); publishers.add(publisher); configurationManagers.put(publisher.getComponent(), new DistributedConfigurationManager(publisher.getComponent())); System.clearProperty(OODT_PROJECT); } }
Example 3
Source Project: spring-analysis-note File: ServerEndpointExporter.java License: MIT License | 6 votes |
/** * Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}. */ protected void registerEndpoints() { Set<Class<?>> endpointClasses = new LinkedHashSet<>(); if (this.annotatedEndpointClasses != null) { endpointClasses.addAll(this.annotatedEndpointClasses); } ApplicationContext context = getApplicationContext(); if (context != null) { String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class); for (String beanName : endpointBeanNames) { endpointClasses.add(context.getType(beanName)); } } for (Class<?> endpointClass : endpointClasses) { registerEndpoint(endpointClass); } if (context != null) { Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class); for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) { registerEndpoint(endpointConfig); } } }
Example 4
Source Project: springboot-plugin-framework-parent File: AopUtils.java License: Apache License 2.0 | 6 votes |
/** * 解决AOP无法代理到插件类的问题 * @param applicationContext 插件包装类 */ public static synchronized void registered(ApplicationContext applicationContext) { Map<String, ProxyProcessorSupport> beansOfType = applicationContext .getBeansOfType(ProxyProcessorSupport.class); if(beansOfType.isEmpty()){ LOG.warn("Not found ProxyProcessorSupports, And Plugin AOP can't used"); return; } for (ProxyProcessorSupport support : beansOfType.values()) { if(support == null){ continue; } ProxyWrapper proxyWrapper = new ProxyWrapper(); proxyWrapper.setProxyProcessorSupport(support); PROXY_WRAPPERS.add(proxyWrapper); } }
Example 5
Source Project: joinfaces File: SpringBootServiceLocator.java License: Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> Collection<Class<T>> locate(Class<T> clazz) { Set<Class<T>> result = new LinkedHashSet<Class<T>>(); // use the Spring API to obtain the WebApplicationContext ApplicationContext context = ApplicationContextProvider.getApplicationContext(); // may be null if Spring hasn't started yet if (context != null) { // ask spring about SPI implementations Map<String, T> beans = context.getBeansOfType(clazz); // add the implementations Class objects to the result set for (T type : beans.values()) { result.add((Class<T>) type.getClass()); } } return result; }
Example 6
Source Project: spring4-understanding File: ContextNamespaceHandlerTests.java License: Apache License 2.0 | 6 votes |
@Test public void propertyPlaceholderSystemProperties() throws Exception { String value = System.setProperty("foo", "spam"); try { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "contextNamespaceHandlerTests-system.xml", getClass()); Map<String, PropertyPlaceholderConfigurer> beans = applicationContext .getBeansOfType(PropertyPlaceholderConfigurer.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); assertEquals("spam", applicationContext.getBean("string")); assertEquals("none", applicationContext.getBean("fallback")); } finally { if (value != null) { System.setProperty("foo", value); } } }
Example 7
Source Project: AlgoTrader File: GrailsDataBinder.java License: GNU General Public License v2.0 | 6 votes |
private void bindWithRequestAndPropertyValues(ServletRequest request, MutablePropertyValues mpvs) { GrailsWebRequest webRequest = GrailsWebRequest.lookup((HttpServletRequest) request); if (webRequest != null) { final ApplicationContext applicationContext = webRequest.getApplicationContext(); if (applicationContext != null) { final Map<String, BindEventListener> bindEventListenerMap = applicationContext.getBeansOfType(BindEventListener.class); for (BindEventListener bindEventListener : bindEventListenerMap.values()) { bindEventListener.doBind(getTarget(), mpvs, getTypeConverter()); } } } preProcessMutablePropertyValues(mpvs); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; bindMultipart(multipartRequest.getMultiFileMap(), mpvs); } doBind(mpvs); }
Example 8
Source Project: metrics File: GaugeRegistry4SpringContext.java License: Apache License 2.0 | 6 votes |
@Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext(); //仅在root application context启动后执行 if (applicationContext.getParent() != null) { return; } Map<String, Object> beansOfType = applicationContext.getBeansOfType(Object.class); for (Object bean : beansOfType.values()) { if (bean == null) { return; } Class<?> targetClass = AopUtils.getTargetClass(bean); Method[] methods = targetClass.getMethods(); if (methods == null || methods.length == 0) { return; } for (Method method : methods) { EnableGauge aliGaugeAnnotation = method.getAnnotation(EnableGauge.class); if (aliGaugeAnnotation == null) { continue; } GaugeRegistry.registerGauge(aliGaugeAnnotation, bean, method); } } }
Example 9
Source Project: java-technology-stack File: WebMvcConfigurationSupportTests.java License: MIT License | 6 votes |
@Test public void emptyHandlerMappings() { ApplicationContext context = initContext(WebConfig.class); Map<String, HandlerMapping> handlerMappings = context.getBeansOfType(HandlerMapping.class); assertFalse(handlerMappings.containsKey("viewControllerHandlerMapping")); assertFalse(handlerMappings.containsKey("resourceHandlerMapping")); assertFalse(handlerMappings.containsKey("defaultServletHandlerMapping")); Object nullBean = context.getBean("viewControllerHandlerMapping"); assertTrue(nullBean.equals(null)); nullBean = context.getBean("resourceHandlerMapping"); assertTrue(nullBean.equals(null)); nullBean = context.getBean("defaultServletHandlerMapping"); assertTrue(nullBean.equals(null)); }
Example 10
Source Project: hasting File: RpcProviderProcessor.java License: MIT License | 5 votes |
private void initRpcServer(ApplicationContext apc){ Map<String, AbstractRpcServer> servers = apc.getBeansOfType(AbstractRpcServer.class); Set<String> keys = servers.keySet(); for(String key:keys){ if(!StringUtils.hasText(key)){ key = DEFAULT_RPC_BEAN; } AbstractRpcServer server = servers.get(key); serverMap.put(key, server); logger.info("find rpc service:"+key+" host:"+server.getHost()+":"+server.getPort()); } }
Example 11
Source Project: yanwte2 File: SpringDataExtensionInitializerLocator.java License: Apache License 2.0 | 5 votes |
@Override public Set<DataExtensionInitializer<ExtensibleData, ?>> getInitializers() { ApplicationContext applicationContext = SpringHook.getApplicationContext(); @SuppressWarnings("unchecked") Map<String, DataExtensionInitializer<ExtensibleData, ?>> beansOfType = (Map) applicationContext.getBeansOfType(DataExtensionInitializer.class); if (beansOfType != null) { Collection<DataExtensionInitializer<ExtensibleData, ?>> initializers = beansOfType.values(); return ImmutableSet.copyOf(initializers); } return ImmutableSet.of(); }
Example 12
Source Project: molgenis File: JobFactoryRegistrar.java License: GNU Lesser General Public License v3.0 | 4 votes |
public void register(ContextRefreshedEvent event) { ApplicationContext ctx = event.getApplicationContext(); Map<String, JobFactory> jobFactoryMap = ctx.getBeansOfType(JobFactory.class); jobFactoryMap.values().forEach(this::register); }
Example 13
Source Project: molgenis File: ScriptRunnerRegistrar.java License: GNU Lesser General Public License v3.0 | 4 votes |
public void register(ContextRefreshedEvent event) { ApplicationContext ctx = event.getApplicationContext(); Map<String, ScriptRunner> scriptRunnerMap = ctx.getBeansOfType(ScriptRunner.class); scriptRunnerMap.values().forEach(this::register); }
Example 14
Source Project: molgenis File: ExceptionResponseGeneratorRegistrar.java License: GNU Lesser General Public License v3.0 | 4 votes |
public void register(ApplicationContext applicationContext) { Map<String, ExceptionResponseGenerator> responseGeneratorMap = applicationContext.getBeansOfType(ExceptionResponseGenerator.class); responseGeneratorMap.values().forEach(this::registerResponseGenerator); }
Example 15
Source Project: velocity-spring-boot-project File: EmbeddedVelocityViewResolverApplicationListener.java License: Apache License 2.0 | 3 votes |
@Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext applicationContext = event.getApplicationContext(); Map<String, EmbeddedVelocityViewResolver> viewResolverMap = applicationContext.getBeansOfType(EmbeddedVelocityViewResolver.class); for (EmbeddedVelocityViewResolver viewResolver : viewResolverMap.values()) { viewResolver.setViewClass(EmbeddedVelocityToolboxView.class); } }
Example 16
Source Project: cia File: AdminCountryView.java License: Apache License 2.0 | 2 votes |
/** * Instantiates a new admin country view. * * @param context * the context */ public AdminCountryView(final ApplicationContext context) { super(context.getBeansOfType(PageModeContentFactory.class), NAME); }
Example 17
Source Project: cia File: AdminApplicationConfigurationView.java License: Apache License 2.0 | 2 votes |
/** * Instantiates a new admin application configuration view. * * @param context * the context */ public AdminApplicationConfigurationView(final ApplicationContext context) { super(context.getBeansOfType(PageModeContentFactory.class), NAME); }
Example 18
Source Project: cia File: DocumentsView.java License: Apache License 2.0 | 2 votes |
/** * Instantiates a new document view. * * @param context * the context */ public DocumentsView(final ApplicationContext context) { super(context.getBeansOfType(PageModeContentFactory.class), NAME); }
Example 19
Source Project: cia File: AgentOperationView.java License: Apache License 2.0 | 2 votes |
/** * Instantiates a new agent operation view. * * @param context * the context */ public AgentOperationView(final ApplicationContext context) { super(context.getBeansOfType(PageModeContentFactory.class), NAME); }
Example 20
Source Project: cia File: MinistryView.java License: Apache License 2.0 | 2 votes |
/** * Instantiates a new ministry view. * * @param context * the context */ public MinistryView(final ApplicationContext context) { super(context.getBeansOfType(PageModeContentFactory.class), NAME); }