waterye

Spring集成Groovy

2.0 M2 新增Package org.springframework.scripting, 集成了bsh, groovy, jruby, 这里只关心groovy

1. xml
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>

    
<bean id="calculator" class="org.springframework.scripting.groovy.GroovyScriptFactory">
        
<constructor-arg>
            
<value>inline:
package org.springframework.scripting.groovy;
import org.springframework.scripting.Calculator
class GroovyCalculator implements Calculator {
    int add(int x, int y) {
       return x + y;
    }
}
            
</value>
        
</constructor-arg>
    
</bean>

    
<bean id="messenger" class="org.springframework.scripting.groovy.GroovyScriptFactory">
        
<constructor-arg value="classpath:org/springframework/scripting/groovy/Messenger.groovy"/>
        
<property name="message" value="Hello World!"/>
    
</bean>
在xml中写groovy, 灵活得有点过头(维护麻烦)

2. groovy
package org.springframework.scripting.groovy;

import org.springframework.scripting.Messenger

class GroovyMessenger implements Messenger {

    @Property String message;
}

3. test case
ApplicationContext ctx =
                
new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyContext.xml");
        Calculator calc 
= (Calculator) ctx.getBean("calculator");
        Messenger messenger 
= (Messenger) ctx.getBean("messenger");

上面的代码出处: spring-framework-2.0-m2\test\org\springframework\scripting\groovy

posted on 2006-02-06 22:57 waterye 阅读(4375) 评论(5)  编辑  收藏 所属分类: spring

Feedback

# re: Spring集成Groovy 2006-02-07 09:11 mmwy

HOHO,幸福终于来了,再不用去cvs里面下spring modules代码了
  回复  更多评论   

# re: Spring集成Groovy 2006-02-07 19:47 江南白衣

有没有实用一点的例子?  回复  更多评论   

# re: Spring集成Groovy 2006-02-07 19:59 Water Ye

还没有, 不过我更喜欢grails对spring的那种封装方式  回复  更多评论   

# re: Spring集成Groovy 2008-02-21 12:29 老龙

请问org.springframework.scripting是在哪个JAR文件里面?
知道的大哥能否发个邮件给我?shaoanfeng@163.com谢谢.  回复  更多评论   

# re: Spring集成Groovy 2008-02-21 13:07 老龙

找到了,在spring.jar中  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: