I'm trying to access a bean reference in a @PreAuthorize annotation as follows:
@PreAuthorize("@testBean.getTestValue()")
public String testSpEL() {
....
}
I have a test bean configured as follows:
@Component(value="testBean")
public class TestBean {
public boolean getTestValue() {
return true;
}
}
When I try to access the testSpEL() method however, I'm confronted with the following exception:
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'testBean'
at org.springframework.expression.spel.ast.BeanReference.getValueInternal(BeanReference.java:45)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97)
at org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:11)
I have thoroughly done my research but I can't find anywhere what I need to change in my configuration to get this to work. Any pointers?
Thanks!
Kind regards, Jonck
P.S. I'm using Spring 3.0.5. The following seems to indicate this type of functionality should work: