发布于 2016-08-20 09:16:50 | 141 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Spring Framework 开源j2ee框架

Spring是什么呢?首先它是一个开源的项目,而且目前非常活跃;它是一个基于IOC和AOP的构架多层j2ee系统的框架,但它不强迫你必须在每一层 中必须使用Spring,因为它模块化的很好,允许你根据自己的需要选择使用它的某一个模块;它实现了很优雅的MVC,对不同的数据访问技术提供了统一的接口,采用IOC使得可以很容易的实现bean的装配,提供了简洁的AOP并据此实现Transcation Managment,等等


这篇文章主要介绍了通过spring用beanshell实现java接口示例,需要的朋友可以参考下

说明

1.通过脚本语言让JAVA执行动态代码
2.用Spring可以将脚本语言代理成Java接口的实现类
3.Spring2.5.6中支持三种脚本语言ruby,Groovy,BeanShell
4.示例中为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);
}



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务