First they ignore you
then they ridicule you
then they fight you
then you win
    -- Mahatma Gandhi
Chinese => English     英文 => 中文             
随笔-143  评论-745  文章-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, Grails'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 山风小子 阅读(291) 评论(2)  编辑  收藏 所属分类: Groovy & Grails

评论:
# re: [转载]Contrasting Grails SpringBuilder vs JRuby Spring DSL vs Guice 2007-04-19 08:38 | 静儿
您这两篇转载的文章我都看了,虽然不是太懂,可我觉得它们都是很好的文章。和我做的毕业设计也有联系的。等过几天我的知识长进了,我再重新拜读这两篇大作。呵呵!  回复  更多评论
  
# re: [转载]Contrasting Grails SpringBuilder vs JRuby Spring DSL vs Guice 2007-04-19 08:50 | 山风小子
@静儿
呵呵~欢迎再来 :)  回复  更多评论
  



标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-04-19 06:18 编辑过