Grails 2.0.4 - 使用带有 inlist 约束和动态查找器的动态脚手架。
我正在尝试在域对象的 inList 约束中使用动态查找器。如果我在应用程序处于活动状态时通过 run-app 更改约束以 sample 2 = Aidy.findAll()*.code 它可以很好地从引导的示例数据中创建对象表单的下拉列表。但是,随后使用 grails run-app 引导应用程序失败并出现 MissingMethodException。
//1- aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
//2- aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())
在域的 inlist 约束中使用 findAll 是个坏主意吗?有什么建议/建议吗?
缩写错误是
$ grails run-app
| Running Grails application
| Error 2012-11-09 12:54:16,589 [pool-5-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
....
....
...
我有一个简单的示例项目:https ://github.com/mlmclaug/scaffold_inlist.git 但它只是以下 2 个域对象、一个控制器和一个 bootstrap.groovy
package edu.uvm
class Aidy {
String code
String desc
Date startDate
Date endDate
String statusInd
static constraints = {
code(unique:true,blank:false, maxSize:4)
desc(blank:false, maxSize:30)
startDate(blank:false)
endDate(blank:false)
statusInd(blank:false, inList:["A","I"])
}
}
package edu.uvm
class TreqMap {
String aidyear
String treq
Integer seqno
static constraints = {
aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
//aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())
treq(blank:false, maxSize:6, inList:["BNOTE","SCERT","PERKIN","PNOTE","LNOTE","SNOTE"])
seqno(blank:true, range:0..99)
}
}
package edu.uvm
class TreqMapController {
def scaffold = edu.uvm.TreqMap
}
import edu.uvm.Aidy
class BootStrap {
def init = { servletContext ->
new Aidy(code:'0910', desc:'July 2009 - June 2010', startDate:'07/01/2009', endDate:'06/30/2010', statusInd:'A').save(failOnError:true)
new Aidy(code:'1011', desc:'July 2010 - June 2011', startDate:'07/01/2010', endDate:'06/30/2011', statusInd:'A').save(failOnError:true)
new Aidy(code:'1112', desc:'July 2011 - June 2012', startDate:'07/01/2011', endDate:'06/30/2012', statusInd:'A').save(flush:true,failOnError:true)
println "Loaded " + Aidy.count() + " Aid Years"
}
def destroy = {
}
}