Java Code Examples for org.springframework.beans.factory.support.DefaultListableBeanFactory#setBeanExpressionResolver()
The following examples show how to use
org.springframework.beans.factory.support.DefaultListableBeanFactory#setBeanExpressionResolver() .
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: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExpressionInStringArray() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class); given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class))) .willReturn("classpath:/org/springframework/beans/factory/xml/util.properties"); bf.setBeanExpressionResolver(beanExpressionResolver); RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("locations", new String[]{"#{foo}"}); rbd.setPropertyValues(pvs); bf.registerBeanDefinition("myProperties", rbd); Properties properties = (Properties) bf.getBean("myProperties"); assertEquals("bar", properties.getProperty("foo")); }
Example 2
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testExpressionInStringArray() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class); when(beanExpressionResolver.evaluate(eq("#{foo}"), ArgumentMatchers.any(BeanExpressionContext.class))) .thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties"); bf.setBeanExpressionResolver(beanExpressionResolver); RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("locations", new String[]{"#{foo}"}); rbd.setPropertyValues(pvs); bf.registerBeanDefinition("myProperties", rbd); Properties properties = (Properties) bf.getBean("myProperties"); assertEquals("bar", properties.getProperty("foo")); }
Example 3
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testExpressionInStringArray() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class); when(beanExpressionResolver.evaluate(eq("#{foo}"), Matchers.any(BeanExpressionContext.class))) .thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties"); bf.setBeanExpressionResolver(beanExpressionResolver); RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("locations", new String[]{"#{foo}"}); rbd.setPropertyValues(pvs); bf.registerBeanDefinition("myProperties", rbd); Properties properties = (Properties) bf.getBean("myProperties"); assertEquals("bar", properties.getProperty("foo")); }
Example 4
Source File: DataDictionary.java From rice with Educational Community License v2.0 | 5 votes |
/** * Sets up the bean post processor and conversion service * * @param beans - The bean factory for the the dictionary beans */ public static void setupProcessor(DefaultListableBeanFactory beans) { try { // UIF post processor that sets component ids BeanPostProcessor idPostProcessor = ComponentBeanPostProcessor.class.newInstance(); beans.addBeanPostProcessor(idPostProcessor); beans.setBeanExpressionResolver(new StandardBeanExpressionResolver() { @Override protected void customizeEvaluationContext(StandardEvaluationContext evalContext) { try { evalContext.registerFunction("getService", ExpressionFunctions.class.getDeclaredMethod("getService", new Class[]{String.class})); } catch(NoSuchMethodException me) { LOG.error("Unable to register custom expression to data dictionary bean factory", me); } } }); // special converters for shorthand map and list property syntax GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(new StringMapConverter()); conversionService.addConverter(new StringListConverter()); beans.setConversionService(conversionService); } catch (Exception e1) { throw new DataDictionaryException("Cannot create component decorator post processor: " + e1.getMessage(), e1); } }