List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerSingleton
void registerSingleton(String beanName, Object singletonObject);
From source file:org.springframework.integration.handler.ExpressionEvaluatingMessageProcessorTests.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/*www .j a v a2 s.c o m*/ public void testProcessMessageWithParameterCoercionToNonPrimitive() throws Exception { class TestTarget { @SuppressWarnings("unused") public String find(Resource[] resources) { return Arrays.asList(resources).toString(); } } Expression expression = expressionParser.parseExpression("#target.find(payload)"); ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); ConfigurableListableBeanFactory beanFactory = new GenericApplicationContext().getBeanFactory(); processor.setBeanFactory(beanFactory); IntegrationEvaluationContextFactoryBean factoryBean = new IntegrationEvaluationContextFactoryBean(); factoryBean.setBeanFactory(beanFactory); beanFactory.registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, factoryBean.getObject()); processor.afterPropertiesSet(); EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); String result = (String) processor.processMessage(new GenericMessage<String>("classpath*:*.properties")); assertTrue("Wrong result: " + result, result.contains("log4j.properties")); }
From source file:org.springframework.integration.test.util.TestUtils.java
private static void registerBean(String beanName, Object bean, BeanFactory beanFactory) { Assert.notNull(beanName, "bean name must not be null"); ConfigurableListableBeanFactory configurableListableBeanFactory = null; if (beanFactory instanceof ConfigurableListableBeanFactory) { configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory; } else if (beanFactory instanceof GenericApplicationContext) { configurableListableBeanFactory = ((GenericApplicationContext) beanFactory).getBeanFactory(); }/* w w w .j a va2 s . c o m*/ if (bean instanceof BeanNameAware) { ((BeanNameAware) bean).setBeanName(beanName); } if (bean instanceof BeanFactoryAware) { ((BeanFactoryAware) bean).setBeanFactory(beanFactory); } if (bean instanceof InitializingBean) { try { ((InitializingBean) bean).afterPropertiesSet(); } catch (Exception e) { throw new FatalBeanException("failed to register bean with test context", e); } } configurableListableBeanFactory.registerSingleton(beanName, bean); //NOSONAR false positive }