刚开始接触beanshell执行语言,现在的spring对BeanShell、Groovy、JavaScript动态脚本语言都有支持的。 以下是对beanshell的一个小demo:
package cn.hr.controller; import org.junit.Test; import org.springframework.scripting.bsh.BshScriptUtils; import bsh.EvalError; public class TestBeanShell { @Test public void testShell() { String srciptText = "say(name){ return \"hello,\"+name;}"; SayHello sh; try { sh = (SayHello) BshScriptUtils.createBshObject(srciptText, new Class[] { SayHello.class }); String res=sh.say("小李子"); System.out.println(res); } catch (EvalError e) { // TODO Auto-generated catch block e.printStackTrace(); } } }大家记得下载 bsh-2.0b4.jar包哟! 链接:http://www.beanshell.org/download.html 下载的时候,如果是公司网络会有些慢。多下载几次就好了。
