I want to inject a guava Predicate into my bean, which should be an equalto inside a not.
I tried this:
<bean id="bla" class="something">
<property name="indexPredicate" value="#{T(com.google.common.base.Predicates).not(T(com.google.common.base.Predicates).equalTo(145028) )}" />
</bean>
But it throws exception:
Caused by: org.springframework.expression.spel.SpelParseException: EL1049E:(pos 36): Unexpected data after '.': 'not(!)'
Spring 3.0.5, Guava 11.0.2
How can I make it work?
Apparently SpEL thinks you mean the Operator not
. However, I don't see any way to escape or disambiguate that in the documentation. Perhaps you need to file a feature request for that.
Alternatively, here is the pre-3.0 factory-method approach. It's horrible, I know, but it might be an acceptable workaround in your case:
<property name="indexPredicate">
<bean class="com.google.common.base.Predicates" factory-method="not">
<constructor-arg>
<bean class="com.google.common.base.Predicates"
factory-method="equalTo">
<constructor-arg>
<bean class="java.lang.Integer" factory-method="valueOf">
<constructor-arg value="145028" />
</bean>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>