@Test public void testAddingRemovingAccessors() { StandardEvaluationContext ctx = new StandardEvaluationContext(); // reflective property accessor is the only one by default List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors(); assertEquals(1,propertyAccessors.size()); StringyPropertyAccessor spa = new StringyPropertyAccessor(); ctx.addPropertyAccessor(spa); assertEquals(2,ctx.getPropertyAccessors().size()); List<PropertyAccessor> copy = new ArrayList<>(); copy.addAll(ctx.getPropertyAccessors()); assertTrue(ctx.removePropertyAccessor(spa)); assertFalse(ctx.removePropertyAccessor(spa)); assertEquals(1,ctx.getPropertyAccessors().size()); ctx.setPropertyAccessors(copy); assertEquals(2,ctx.getPropertyAccessors().size()); }
@Init public void init() { if (null == beanFactory) { log.error("Spring context not found, can't use spring expression factory"); return; } SpelParserConfiguration c = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this.getClass().getClassLoader()); spelParser = new SpelExpressionParser(c); evalContext = new StandardEvaluationContext(); envProperty = new EnvPropertyAccessor(env); evalContext.getPropertyAccessors().add(0, envProperty); evalContext.getPropertyAccessors().add(0, new MapPropertyAccessor()); evalContext.setBeanResolver(new BeanFactoryResolver(beanFactory)); }
@Override public EvaluationContext createContext(Object rootObject) { StandardEvaluationContext context = new StandardEvaluationContext(rootObject); context.setVariables(getVariableValues(rootObject)); context.setTypeConverter(new StandardTypeConverter(conversionService)); context.getPropertyAccessors().addAll(propertyAccessors); return context; }
@Override public EvaluationContext createContext(Object rootObject) { StandardEvaluationContext context = new StandardEvaluationContext(rootObject); context.setVariables(getVariableValues(rootObject)); context.setTypeConverter(new StandardTypeConverter(conversionService)); context.getPropertyAccessors().addAll(propertyAccessors); return context; }