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 閱讀(4406) 評論(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文件里面?
          知道的大哥能否發(fā)個郵件給我?shaoanfeng@163.com謝謝.  回復  更多評論   

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

          找到了,在spring.jar中  回復  更多評論   

          主站蜘蛛池模板: 台江县| 罗山县| 永平县| 呼图壁县| 南华县| 石城县| 大城县| 岑溪市| 多伦县| 金川县| 绥阳县| 宣威市| 清涧县| 庆安县| 闸北区| 潜江市| 洛阳市| 孝感市| 沅陵县| 平南县| 平阴县| 福建省| 保定市| 青海省| 永靖县| 曲麻莱县| 广宁县| 辛集市| 老河口市| 乌拉特中旗| 珠海市| 准格尔旗| 桑植县| 金秀| 仙居县| 海口市| 都匀市| 察隅县| 黎平县| 连平县| 河池市|