通过spring用beanshell实现java接口示例 说明1.通过脚本语言让JAVA执行动态代码2.用Spring可以将脚本语言代理成Java接口的实现类3.Spring2.5.6中支持三种脚本语言ruby,Groovy,BeanShell4.示例中为spring与beanshell结合5.依赖spring2.5.6,bsh-2.0b4 复制代码 代码如下: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("vidy"); System.out.println(res); } catch (EvalError e) { // TODO Auto-generated catch block e.printStackTrace(); } }}interface SayHello { public String say(String name);}