2010-05-11 94 views
2

我的Grails应用从spring/resources.groovyGrails领域类的初始化

calendarService(CalendarService) { bean -> 
    bean.initMethod = "init"  
} 

定义了如下的Spring bean这种方法看起来是这样的:

class CalendarService { 
    void init() { 
     User.findByEmail("[email protected]") 
    } 
} 

当我调用动态取景器findByEmail我得到一个MissingMethodException。我的猜测是,我想尽早调用这个方法,即在域类有动态发现者添加到他们的元类之前。一种解决方案是从Bootstrap.init自己拨打CalendarService.init(),而不是指示Spring来调用它,但有没有更好的解决方案?

谢谢, 唐

回答

3

你是对的,因为在这个post描述,如果你需要的动态方法,你最好与BootStrap.groovy中去,没有任何

BootStrap { 
    def calendarService 
    def init() { 
     calendarService.init() 
    } 
} 
0

以下作品config in resources.groovy

class CalendarService { 

    @PostConstruct 
    private void init() { 
     User.findByEmail("[email protected]") 
    } 
}