Closed
Description
matthew inger opened SPR-9511 and commented
Status Quo
Currently, if you try to reference a FactoryBean
in a SpEL expression using standard syntax, you get an error as follows.
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.IllegalStateException: Cannot handle (38) '&'
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:142)
at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1299)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:224)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:311)
... 45 more
Caused by: java.lang.IllegalStateException: Cannot handle (38) '&'
at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:193)
at org.springframework.expression.spel.standard.Tokenizer.<init>(Tokenizer.java:47)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:110)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:128)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:74)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:64)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:119)
... 48 more
Work-Around
I can work around this by injecting the AnnotationSessionFactoryBean
into my initializer, but that will break when I move to Hibernate 4. Alternatively, I could use a BeanReferenceFactoryBean
and get the BeanFactory
to retrieve a named bean and then use SpEL from there. Either seems like a hack, and SpEL should support this IMHO.
Example Code
Here's the relevant XML configuration:
<bean id="entityCallbackHandler" class="org.hibernate.ejb.event.EntityCallbackHandler "/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
</bean>
<bean id="entityCallbackHandlerInitializer"
class="hibernate.utilities.EntityCallbackHandlerInitializer">
<property name="entityCallbackHandler" ref="entityCallbackHandler" />
<property name="configuration" value="#{&sessionFactory.configuration}" />
</bean>
And the java code for the initializer class:
public class EntityCallbackHandlerInitializer {
private Configuration configuration;
private EntityCallbackHandler entityCallbackHandler;
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
public void setEntityCallbackHandler(EntityCallbackHandler entityCallbackHandler) {
this.entityCallbackHandler = entityCallbackHandler;
}
@PostConstruct
public void init() throws ClassNotFoundException {
final ReflectionManager reflectionManager = configuration.getReflectionManager();
final Iterator<PersistentClass> classMappings = configuration.getClassMappings();
while (classMappings.hasNext()) {
entityCallbackHandler.add(
reflectionManager.classForName(classMappings.next().getClassName(), this.getClass()),
reflectionManager);
}
}
}
Issue Links:
- SpEl does not support conjunction (&&) and disjunction (||) logic [SPR-7652] #12308 SpEl does not support conjunction (&&) and disjunction (||) logic