简体   繁体   English

Java groovy脚本中的“ bsf”关键字

[英]“bsf” keyword in groovy scripting in java

I'm using groovy scripting in java. 我在Java中使用Groovy脚本。 Here is how it operates: I'm creating in java BSFManager, then register some beans, then I receive groovy script from the input and pass it for execution to BSFManager instance. 它的工作方式如下:我在Java BSFManager中创建,然后注册一些bean,然后从输入中接收groovy脚本并将其传递给BSFManager实例执行。 There is something I don't understand. 我有些不懂 When I want to operate on class instances (beans) that I previously registered to BSFManager in my java code in my groovy script, I must use some special word 'bsf' to adress to BSFManager in my groovy script. 当我想对以前在groovy脚本中的Java代码中注册到BSFManager的类实例(bean)进行操作时,我必须使用一些特殊的单词'bsf'来访问groovy脚本中的BSFManager。 Eg bsf.lookupBean("mybeanname") . 例如bsf.lookupBean("mybeanname") I didn't found any definition of that special word "bsf", but it seems to work. 我没有找到该特殊单词“ bsf”的任何定义,但它似乎有效。 So what is the origin of that hidden bsf variable or where is it declared? 那么,这个隐藏的bsf变量的起源是什么?在哪里声明呢?

BSF is short for Bean Scripting Framework , which is an Apache project for embedding scripting languages within Java applications. BSF是Bean Scripting Framework的缩写,它是一个Apache项目,用于在Java应用程序中嵌入脚本语言。

The bsf object is created as part of that framework. bsf对象是作为该框架的一部分创建的。

From the manual: 从手册中:

Additionally, BSF declares an object named bsf within a scripting engine's execution context, which represents the BSFManager that is associated with the scripting engine. 此外,BSF在脚本引擎的执行上下文中声明了一个名为bsf的对象,该对象表示与脚本引擎关联的BSFManager。 This object provides all of the methods and properties associated with the BSFManager to the script. 该对象将与BSFManager关联的所有方法和属性提供给脚本。 However, the most used method within scripts is usually lookupBean(), which is used to access objects in BSF's object registry. 但是,脚本中最常用的方法通常是lookupBean(),该方法用于访问BSF对象注册表中的对象。

The Apache Commons BSF manual Apache Commons BSF手册

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

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