First they ignore you
          then they ridicule you
          then they fight you
          then you win
              -- Mahatma Gandhi
          Chinese => English     英文 => 中文             
          隨筆-221  評論-1047  文章-0  trackbacks-0
          An interesting post by Craig Walls that I hadn't noticed before shows how you can create Spring configs with a little JRuby DSL:

          DAOS = [ :ZoneDAO, :EmailDomainDAO, :DayDAO, :PreferenceDAO,
          ???????????????? :WhatEverDao... ]
          DAOS.each do |dao|
          bean(dao, "daos.hibernate.#{dao}Hibernate")
          {|b| b.new("sonarSession")}
          end

          The Groovy version with Grails' SpringBuilder would look like:

          def DAOS = [ZoneDAO, EmailDomainDAO, DayDAO, PreferenceDAO, WhateverDAO]
          DAOs.each { dao ->
          "${dao}"("daos.hibernate.${dao.simpleName}Hibernate") {
          sessionFactory = ref("sonarSession")
          }
          }

          Another important difference between the two is that Springy, the JRuby version, serializes the JRuby code into XML and then reads the beans from that. We used to do this in Grails, but it had serious performance implications for load time, BeanBuilder constructs the ApplicationContext programmatically on the fly.

          Bob Lee also offered his alternative using Guice:

          Class[] daos = { ZoneDao.class, EmailDomainDao.class, PreferenceDao.class... };
          for (Class dao : daos)
          bind(dao).to(Class.forName("daos.hibernate.Hibernate" + dao.getSimpleName()));

          Since Groovy does annotations it is possible to make this code even Groovier:

          def daos = [ZoneDao, EmailDomainDao, PreferenceDao...]
          daos.each { bind(it).to(Class.forName("daos.hibernate.Hibernate${it.simpleName}") }

          原文地址:http://graemerocher.blogspot.com/2007/04/contrasting-grails-springbuilder-vs.html
          posted on 2007-04-19 06:13 山風小子 閱讀(774) 評論(2)  編輯  收藏 所屬分類: Groovy & Grails
          主站蜘蛛池模板: 永城市| 文昌市| 陵水| 孝感市| 阿拉尔市| 桑植县| 岳普湖县| 句容市| 黄大仙区| 东明县| 增城市| 尼玛县| 兴国县| 临颍县| 隆德县| 江门市| 泰来县| 城步| 山西省| 图片| 和平区| 临西县| 宁安市| 怀来县| 城固县| 合川市| 灯塔市| 石林| 林芝县| 瓮安县| 衡山县| 叙永县| 措美县| 赣州市| 湘乡市| 舟曲县| 朔州市| 连江县| 巩留县| 芜湖县| 上犹县|