org.springframework.beans.factory.support.StaticListableBeanFactory Java Examples
The following examples show how to use
org.springframework.beans.factory.support.StaticListableBeanFactory.
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 File: AbstractEmailProcessor.java From nifi with Apache License 2.0 | 6 votes |
/** * Builds and initializes the target message receiver if necessary (if it's * null). Upon execution of this operation the receiver is fully functional * and is ready to receive messages. */ private synchronized void initializeIfNecessary(ProcessContext context, ProcessSession processSession) { if (this.messageReceiver == null) { this.processSession = processSession; this.messageReceiver = this.buildMessageReceiver(context); this.shouldSetDeleteFlag = context.getProperty(SHOULD_DELETE_MESSAGES).asBoolean(); int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger(); this.messageReceiver.setMaxFetchSize(fetchSize); this.messageReceiver.setJavaMailProperties(this.buildJavaMailProperties(context)); // need to avoid spring warning messages this.messageReceiver.setBeanFactory(new StaticListableBeanFactory()); this.messageReceiver.afterPropertiesSet(); this.messageQueue = new ArrayBlockingQueue<>(fetchSize); } }
Example #2
Source File: KualiModuleServiceImplTest.java From rice with Educational Community License v2.0 | 6 votes |
@Before public void installRiceKualiModuleService() throws Exception { GlobalResourceLoader.stop(); SimpleConfig config = new SimpleConfig(); config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID"); ConfigContext.init(config); StaticListableBeanFactory testBf = new StaticListableBeanFactory(); KualiModuleService riceKualiModuleService = mock(KualiModuleService.class); when(riceKualiModuleService.getInstalledModuleServices()).thenReturn(riceModuleServices); testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, riceKualiModuleService); ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf); GlobalResourceLoader.addResourceLoader(rl); GlobalResourceLoader.start(); }
Example #3
Source File: ModuleServiceBaseTest.java From rice with Educational Community License v2.0 | 6 votes |
@Before public void initGRL() throws Exception { GlobalResourceLoader.stop(); SimpleConfig config = new SimpleConfig(); config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID"); ConfigContext.init(config); StaticListableBeanFactory testBf = new StaticListableBeanFactory(); when(kualiModuleService.getInstalledModuleServices()).thenReturn(installedModuleServices); testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, mock(ProviderRegistry.class)); testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, kualiModuleService); ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf); GlobalResourceLoader.addResourceLoader(rl); GlobalResourceLoader.start(); }
Example #4
Source File: AbstractEmailProcessor.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Builds and initializes the target message receiver if necessary (if it's * null). Upon execution of this operation the receiver is fully functional * and is ready to receive messages. */ private synchronized void initializeIfNecessary(ProcessContext context, ProcessSession processSession) { if (this.messageReceiver == null) { this.processSession = processSession; this.messageReceiver = this.buildMessageReceiver(context); this.shouldSetDeleteFlag = context.getProperty(SHOULD_DELETE_MESSAGES).asBoolean(); int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger(); this.messageReceiver.setMaxFetchSize(fetchSize); this.messageReceiver.setJavaMailProperties(this.buildJavaMailProperties(context)); // need to avoid spring warning messages this.messageReceiver.setBeanFactory(new StaticListableBeanFactory()); this.messageReceiver.afterPropertiesSet(); this.messageQueue = new ArrayBlockingQueue<>(fetchSize); } }
Example #5
Source File: BeanFactoryUtilsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNoBeansOfType() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("foo", new Object()); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false); assertTrue(beans.isEmpty()); }
Example #6
Source File: BeanFactoryInvocationHandlerTest.java From rice with Educational Community License v2.0 | 5 votes |
@Before public void createBadInstance() { StaticListableBeanFactory bf = new StaticListableBeanFactory(); bf.addBean("bean", "This is a bean"); bad = (BadInterface) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{BadInterface.class}, new BeanFactoryInvocationHandler(bf)); }
Example #7
Source File: LegacyDataAdapterImplTest.java From rice with Educational Community License v2.0 | 5 votes |
@Before public void setup() throws Exception { GlobalResourceLoader.stop(); SimpleConfig config = new SimpleConfig(); config.putProperty(CoreConstants.Config.APPLICATION_ID, getClass().getName()); ConfigContext.init(config); ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.ENABLE_LEGACY_DATA_FRAMEWORK); ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.KNS_ENABLED); StaticListableBeanFactory testBf = new StaticListableBeanFactory(); testBf.addBean("metadataRepository", metadataRepository); testBf.addBean("dataDictionaryService", dataDictionaryService); testBf.addBean("knsLegacyDataAdapter", knsLegacyDataAdapter); testBf.addBean("kradLegacyDataAdapter", kradLegacyDataAdapter); ResourceLoader rl = new BeanFactoryResourceLoader(new QName(getClass().getName()), testBf); GlobalResourceLoader.addResourceLoader(rl); GlobalResourceLoader.start(); MetadataManager mm = MetadataManager.getInstance(); // register Legacy object ClassDescriptor legacyDescriptor = new ClassDescriptor(mm.getGlobalRepository()); legacyDescriptor.setClassOfObject(Legacy.class); mm.getGlobalRepository().put(Legacy.class, legacyDescriptor); // register LegacyDocument object ClassDescriptor legacyDocumentDescriptor = new ClassDescriptor(mm.getGlobalRepository()); legacyDocumentDescriptor.setClassOfObject(LegacyDocument.class); mm.getGlobalRepository().put(LegacyDocument.class, legacyDocumentDescriptor); }
Example #8
Source File: ModuleConfigurationTest.java From rice with Educational Community License v2.0 | 5 votes |
@Before public void initGRL() throws Exception { GlobalResourceLoader.stop(); SimpleConfig config = new SimpleConfig(); config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID"); ConfigContext.init(config); StaticListableBeanFactory testBf = new StaticListableBeanFactory(); testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, prMock); ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleconfiguration-unittest"), testBf); GlobalResourceLoader.addResourceLoader(rl); GlobalResourceLoader.start(); }
Example #9
Source File: BeanFactoryUtilsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testFindsBeansOfTypeWithStaticFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); TestBean t1 = new TestBean(); TestBean t2 = new TestBean(); DummyFactory t3 = new DummyFactory(); DummyFactory t4 = new DummyFactory(); t4.setSingleton(false); lbf.addBean("t1", t1); lbf.addBean("t2", t2); lbf.addBean("t3", t3); lbf.addBean("t4", t4); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true); assertEquals(4, beans.size()); assertEquals(t1, beans.get("t1")); assertEquals(t2, beans.get("t2")); assertEquals(t3.getObject(), beans.get("t3")); assertTrue(beans.get("t4") instanceof TestBean); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); }
Example #10
Source File: BeanFactoryUtilsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testNoBeansOfType() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("foo", new Object()); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false); assertTrue(beans.isEmpty()); }
Example #11
Source File: BeanFactoryUtilsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testHierarchicalCountBeansWithNonHierarchicalFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("t1", new TestBean()); lbf.addBean("t2", new TestBean()); assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2); }
Example #12
Source File: JCacheInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected JCacheOperationSource createOperationSource(CacheManager cacheManager, CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) { DefaultJCacheOperationSource source = new DefaultJCacheOperationSource(); source.setCacheManager(cacheManager); source.setCacheResolver(cacheResolver); source.setExceptionCacheResolver(exceptionCacheResolver); source.setKeyGenerator(keyGenerator); source.setBeanFactory(new StaticListableBeanFactory()); source.afterPropertiesSet(); source.afterSingletonsInstantiated(); return source; }
Example #13
Source File: ClassPathBeanDefinitionScannerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testBeanAutowiredWithAnnotationConfigEnabled() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class)); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setBeanNameGenerator(new TestBeanNameGenerator()); int beanCount = scanner.scan(BASE_PACKAGE); assertEquals(12, beanCount); context.refresh(); FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class); StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf"); MessageSource ms = (MessageSource) context.getBean("messageSource"); assertTrue(fooService.isInitCalled()); assertEquals("bar", fooService.foo(123)); assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory); assertEquals(2, fooService.listableBeanFactory.size()); assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0)); assertSame(myBf, fooService.listableBeanFactory.get(1)); assertSame(context, fooService.resourceLoader); assertSame(context, fooService.resourcePatternResolver); assertSame(context, fooService.eventPublisher); assertSame(ms, fooService.messageSource); assertSame(context, fooService.context); assertEquals(1, fooService.configurableContext.length); assertSame(context, fooService.configurableContext[0]); assertSame(context, fooService.genericContext); }
Example #14
Source File: BeanFactoryUtilsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testFindsBeansOfTypeWithStaticFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); TestBean t1 = new TestBean(); TestBean t2 = new TestBean(); DummyFactory t3 = new DummyFactory(); DummyFactory t4 = new DummyFactory(); t4.setSingleton(false); lbf.addBean("t1", t1); lbf.addBean("t2", t2); lbf.addBean("t3", t3); lbf.addBean("t4", t4); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true); assertEquals(4, beans.size()); assertEquals(t1, beans.get("t1")); assertEquals(t2, beans.get("t2")); assertEquals(t3.getObject(), beans.get("t3")); assertTrue(beans.get("t4") instanceof TestBean); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); }
Example #15
Source File: BeanFactoryUtilsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testHierarchicalCountBeansWithNonHierarchicalFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("t1", new TestBean()); lbf.addBean("t2", new TestBean()); assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2); }
Example #16
Source File: ClassPathBeanDefinitionScannerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testBeanAutowiredWithAnnotationConfigEnabled() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class)); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setBeanNameGenerator(new TestBeanNameGenerator()); int beanCount = scanner.scan(BASE_PACKAGE); assertEquals(12, beanCount); context.refresh(); FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class); StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf"); MessageSource ms = (MessageSource) context.getBean("messageSource"); assertTrue(fooService.isInitCalled()); assertEquals("bar", fooService.foo(123)); assertEquals("bar", fooService.lookupFoo(123)); assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory); assertEquals(2, fooService.listableBeanFactory.size()); assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0)); assertSame(myBf, fooService.listableBeanFactory.get(1)); assertSame(context, fooService.resourceLoader); assertSame(context, fooService.resourcePatternResolver); assertSame(context, fooService.eventPublisher); assertSame(ms, fooService.messageSource); assertSame(context, fooService.context); assertEquals(1, fooService.configurableContext.length); assertSame(context, fooService.configurableContext[0]); assertSame(context, fooService.genericContext); }
Example #17
Source File: JCacheInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
protected JCacheOperationSource createOperationSource(CacheManager cacheManager, CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) { DefaultJCacheOperationSource source = new DefaultJCacheOperationSource(); source.setCacheManager(cacheManager); source.setCacheResolver(cacheResolver); source.setExceptionCacheResolver(exceptionCacheResolver); source.setKeyGenerator(keyGenerator); source.setBeanFactory(new StaticListableBeanFactory()); source.afterSingletonsInstantiated(); return source; }
Example #18
Source File: JCacheInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
protected JCacheOperationSource createOperationSource(CacheManager cacheManager, CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) { DefaultJCacheOperationSource source = new DefaultJCacheOperationSource(); source.setCacheManager(cacheManager); source.setCacheResolver(cacheResolver); source.setExceptionCacheResolver(exceptionCacheResolver); source.setKeyGenerator(keyGenerator); source.setBeanFactory(new StaticListableBeanFactory()); source.afterSingletonsInstantiated(); return source; }
Example #19
Source File: ClassPathBeanDefinitionScannerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testBeanAutowiredWithAnnotationConfigEnabled() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class)); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setBeanNameGenerator(new TestBeanNameGenerator()); int beanCount = scanner.scan(BASE_PACKAGE); assertEquals(12, beanCount); context.refresh(); FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class); StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf"); MessageSource ms = (MessageSource) context.getBean("messageSource"); assertTrue(fooService.isInitCalled()); assertEquals("bar", fooService.foo(123)); assertEquals("bar", fooService.lookupFoo(123)); assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory); assertEquals(2, fooService.listableBeanFactory.size()); assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0)); assertSame(myBf, fooService.listableBeanFactory.get(1)); assertSame(context, fooService.resourceLoader); assertSame(context, fooService.resourcePatternResolver); assertSame(context, fooService.eventPublisher); assertSame(ms, fooService.messageSource); assertSame(context, fooService.context); assertEquals(1, fooService.configurableContext.length); assertSame(context, fooService.configurableContext[0]); assertSame(context, fooService.genericContext); }
Example #20
Source File: BeanFactoryUtilsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testHierarchicalCountBeansWithNonHierarchicalFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("t1", new TestBean()); lbf.addBean("t2", new TestBean()); assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2); }
Example #21
Source File: BeanFactoryUtilsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testNoBeansOfType() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("foo", new Object()); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false); assertTrue(beans.isEmpty()); }
Example #22
Source File: BeanFactoryUtilsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testFindsBeansOfTypeWithStaticFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); TestBean t1 = new TestBean(); TestBean t2 = new TestBean(); DummyFactory t3 = new DummyFactory(); DummyFactory t4 = new DummyFactory(); t4.setSingleton(false); lbf.addBean("t1", t1); lbf.addBean("t2", t2); lbf.addBean("t3", t3); lbf.addBean("t4", t4); Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true); assertEquals(4, beans.size()); assertEquals(t1, beans.get("t1")); assertEquals(t2, beans.get("t2")); assertEquals(t3.getObject(), beans.get("t3")); assertTrue(beans.get("t4") instanceof TestBean); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true); assertEquals(2, beans.size()); assertEquals(t3, beans.get("&t3")); assertEquals(t4, beans.get("&t4")); }
Example #23
Source File: MethodJmsListenerEndpointTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #24
Source File: MessagingMessageListenerAdapterTests.java From spring-analysis-note with MIT License | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #25
Source File: JmsListenerEndpointRegistrarTests.java From spring-analysis-note with MIT License | 4 votes |
@Before public void setup() { this.registrar.setEndpointRegistry(this.registry); this.registrar.setBeanFactory(new StaticListableBeanFactory()); }
Example #26
Source File: MethodJmsListenerEndpointTests.java From spring-analysis-note with MIT License | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #27
Source File: JmsListenerContainerFactoryIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #28
Source File: JmsListenerContainerFactoryIntegrationTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #29
Source File: MethodJmsListenerEndpointTests.java From java-technology-stack with MIT License | 4 votes |
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) { factory.setBeanFactory(new StaticListableBeanFactory()); factory.afterPropertiesSet(); }
Example #30
Source File: JmsListenerEndpointRegistrarTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Before public void setup() { registrar.setEndpointRegistry(registry); registrar.setBeanFactory(new StaticListableBeanFactory()); }