killme2008 / aviatorscript

A high performance scripting language hosted on the JVM.
http://fnil.net/aviator/
4.44k stars 830 forks source link

加强对 spring 容器的集成插件 #425

Open killme2008 opened 2 years ago

killme2008 commented 2 years ago

方便创建 AviatorEvaluatorInstance 和集成自定义函数等

gxp1317 commented 2 years ago

我提前设置了类加载器: AviatorEvaluatorInstance aviatorEvaluator = AviatorEvaluator.getInstance(); aviatorEvaluator.addFunctionLoader(new SpringContextFunctionLoader(applicationContext)); 想要从加载我的某个service类的某个方法。如下: @Slf4j @Service public class CycleReportServiceImpl implements ICycleReportService { /**

我如何编辑表达式,调用listBizIds? 这样可以吗?正确的写法应该是怎样的? String expression = "cycleReportServiceImpl.listBizIds()"; JSONObject listBizParam = new JSONObject(); listBizParam.put("mainRecordRule",param); AviatorEvaluatorInstance aviatorEvaluator = AviatorEvaluator.getInstance(); aviatorEvaluator.addFunctionLoader(new SpringContextFunctionLoader(applicationContext)); aviatorEvaluator.execute(expression); List bizIds = (List) aviatorEvaluator.execute(expression, listBizParam);

killme2008 commented 2 years ago

@gxp1317 FunctionLoader,顾名思义,加载的是实现了 AviatorFunction 接口的自定义函数。 而如何调用普通类的 Java 方法,这是另一个问题,文档也描述了

https://www.yuque.com/boyan-avfmj/aviatorscript/xbdgg2#rjNeD

whatamazing commented 2 years ago

有考虑支持从spring容器里拿任意实例吗?

852675742 commented 2 years ago

这么调用spring的bean方法?