springspring-el

why does spring's spel have rootObject?


in spel ,if a variable is not prefixed with #, spel will look it in the rootObject. otherwise, spel look it in the context.

why does spring's spel have rootObject ?
can rootObject be treated as a common variable? is it just for convenience?


Solution

  • The context usually is the same for all the evaluation of that expression. The root object is volatile. Think about it as an HTTP request body, where context could be a session for that user. So, root object cannot be as a part of the context since and it cannot be treated as a common variable since. It lives just in a scope of the current expression evaluation.