我有以下 bean 注入(inject)所有 Controller
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)
最佳答案
这是http://jira.grails.org/browse/GRAILS-7800并且是固定的,所以这在 M2 中不会成为问题。作为临时解决方法,您可以导入 bean 的类并显式键入它而不是使用“def”:
import my.DatabaseRepo
class MyController {
DatabaseRepo db
index() {
}
}
关于spring - Grails 2.0 注入(inject) bean 并在 Controller 中出现 ClassCastException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6966603/