简体   繁体   English

spring 如何在内部评估 SPEL?

[英]How spring evaluates SPEL internally?

For example, we have an expression like this 'hasAnyRole("ROLE_1","ROLE_2")'例如,我们有一个像这样的表达式 'hasAnyRole("ROLE_1","ROLE_2")'

I know that Python has a function like eval to run code from a string.我知道 Python 有一个像 eval 一样的 function 从字符串运行代码。 But how it works here?但它在这里是如何工作的? How Spring in Java parses the expression? Java中的Spring如何解析表达式? Does it run it?它运行吗? If yes then how?如果是,那怎么办?

My primary question is how Python runs the string containing the expression.我的主要问题是 Python 如何运行包含表达式的字符串。 How does he understand what to do?他怎么知道该怎么做?

SpEL has a full-blown parser and builds an AST for the expression. SpEL 有一个成熟的解析器并为表达式构建一个 AST。

In this case, the evaluation calls the hasAnyRole() method on the root object for the evaluation.在这种情况下,评估调用根 object 上的hasAnyRole()方法进行评估。

You can dig into the details in a debugger to see the actual workings.您可以在调试器中深入了解细节以查看实际工作情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM