2011-08-06 23 views
1

我有以下豆注入到所有的控制器Grails的2.0注射豆和得到ClassCastException异常错误在控制器

beans = { 
    db(my.DatabaseRepo) { singleton true } 
} 

当我定义

class MyController { 
    def db 
    index() { 
    } 
} 

我有以下错误

java.lang.ClassCastException: my.DatabaseRepo cannot be cast to groovy.lang.Closure 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:680) 

回答

1

这是http://jira.grails.org/browse/GRAILS-7800并且是固定的,所以这在M2中不会成为问题。作为临时的解决方法,您可以导入bean的类并明确地键入它,而不是使用'def':

import my.DatabaseRepo 

class MyController { 

    DatabaseRepo db 

    index() { 
    } 
}