类 NashornHelper

java.lang.Object
net.sohelp.boot.admin.core.db.NashornHelper

@Component public class NashornHelper extends Object
JSR223规范支持

提供基于ScriptEngine的脚本执行能力,当前默认使用GraalVM JavaScript引擎。

从以下版本开始:
2024/06/11 21:43
作者:
AaronFung
  • 构造器详细资料

    • NashornHelper

      public NashornHelper()
  • 方法详细资料

    • getInstance

      @Comment("\u83b7\u53d6\u5b9e\u4f8b") public static NashornHelper getInstance()
      获取NashornHelper单例实例

      通过Spring容器获取已注册的Bean实例。

      返回:
      返回NashornHelper实例
    • support

      @Comment("\u662f\u5426\u652f\u6301") public boolean support(String languageName)
      判断指定语言是否被当前环境支持
      参数:
      languageName - 脚本语言名称(如:"graal.js"、"javascript"等)
      返回:
      若支持则返回true,否则返回false
    • execute

      @Comment("\u6267\u884c") public Object execute(String script, Map<String,Object> context) throws BusiException, ScriptException
      使用默认语言(graal.js/javascript)执行脚本
      参数:
      script - 待执行的脚本字符串
      context - 执行上下文变量映射表
      返回:
      脚本执行结果对象
      抛出:
      BusiException - 当脚本编译或执行过程中发生业务异常时抛出
      ScriptException - 当脚本引擎调用失败时抛出
    • execute

      @Comment("\u6267\u884c") public Object execute(String languageName, String script, Map<String,Object> context) throws Exception
      使用指定语言执行脚本
      参数:
      languageName - 指定使用的脚本语言名称
      script - 待执行的脚本字符串
      context - 执行上下文变量映射表
      返回:
      脚本执行结果对象
      抛出:
      Exception - 当脚本执行过程出现任意异常时抛出