0

I’m trying to understand a piece of Spring code that I need to adapt.
I have:

<bean id="…" class="…">
  <property name="expr"
           value="teams.contains(member.team) and not empty(member.projects)" />
</bean>

The corresponding class has a field

private Expression expr; 

of type

org.apache.commons.jexl2.Expression

Now I am trying to find the appropriate Spring annotation to get rid of the XML file. But I cannot even understand how a simple String property can be injected as a jexl2.Expression object. How does this work?

Yves
  • 21
  • 1
  • 4
  • It seems, that an [Expression is created](https://commons.apache.org/proper/commons-jexl/javadocs/apidocs-2.1/org/apache/commons/jexl2/package-summary.html#example) with `JexlEngine.createExpression("the jexl expression...")`. So now the question may be: how does Spring know that it should call `bean.setExpr(aJexlEngine.createExpression(theValue))` instead of `bean.setExpr(theValue)`; and where does aJexlEngine come from? – Yves Mar 01 '18 at 12:31

1 Answers1

0

A friend found the answer:

There was another XML file with this:

<bean id="bean_for_ExprConverter" class="package.of.custom.ExpressionConverter">
  <constructor-arg ref="bean_for_JexlEngine"/>
</bean>

and also, in the project’s properties:

application.spring.converters = #{{\
  @'bean_for_ExprConverter'\
}}

Thus, as long as the converter bean is defined, it should be enough to simply inject the expression string with the @Value annotation.

Yves
  • 21
  • 1
  • 4