2

私の Grails アプリには、次の Spring Bean が定義されています。spring/resources.groovy

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

このメソッドは次のようになります。

class CalendarService {
    void init() {
        User.findByEmail("foo@doo.com")
    }   
}

動的ファインダーを呼び出すとfindByEmailMissingMethodException. 私の推測では、このメソッドを呼び出すのが早すぎます。つまり、ドメイン クラスのメタクラスに動的ファインダーが追加される前です。1 つの解決策は、Spring に呼び出すように指示するのではなく、CalendarService.init()から自分自身を呼び出すことですが、より良い解決策はありますか?Bootstrap.init

ありがとう、ドン

4

2 に答える 2

3

You're right, as described in this post, if you need the dynamic methods you'd better go with BootStrap.groovy

BootStrap {
    def calendarService
    def init() {
        calendarService.init()
    }
}
于 2010-05-11T13:42:21.680 に答える