当我在我的域类上使用保存操作时,我收到一条带有以下错误的flash消息:
Method on class [com.xxxxxxx.Detail] was used outside of a Grails application.
If running in the context of a test using the mocking API or bootstrap Grails correctly.
运行Grails 2.3.7和Hibernate应该更新得很好。 我的引导工作正常,我能够在其中保存域类实例。但是当我尝试从开发环境中保存一个Detail类实例时,我收到了这个错误。
为什么我收到此错误?有什么想法吗?
谢谢!
BuildConfig.groovy包含:
dependencies {
build "com.google.gwt:gwt:2.5.1"
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2'
compile "org.apache.solr:solr-solrj:4.6.1"
compile "commons-dbcp:commons-dbcp:1.4"
runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
compile "ar.com.fdvs:DynamicJasper:5.0.0"
}
plugins {
// Java 6.0 has this already
runtime(':mail:1.0') { excludes 'mail', 'activiation', 'spring-test' }
runtime ":hibernate:3.6.10.10"
build ":tomcat:7.0.52.1"
compile ":smartgwt:0.2"
build ":extended-dependency-manager:0.5.5"
compile ":gwt:1.0", {
transitive=false
}
compile ":cxf:1.1.1"
compile ":executor:0.3"
compile ":grails-melody:1.48.0"
runtime ":jquery:1.10.2.2"
compile ":modalbox:0.4"
compile ":ofchart:0.6.3"
compile ":quartz:1.0.1"
compile ":remote-pagination:0.4.6"
compile ":richui:0.8"
compile ":spring-security-core:2.0-RC2"
compile ":android-gcm:0.2"
compile ":aws-sdk:1.6.12"
runtime ":resources:1.2.7"
compile ":csv:0.3.1"
compile ":jasper:1.7.0"
compile ":dynamic-jasper:0.6"
compile ":postgresql-extensions:0.6.1"
compile ":modalbox:0.4"
compile ":jquery-ui:1.10.3"
}
错误
2014/03/07 00:20:22 [thread:63] INFO Date - Thu Mar 06 00:00:00 UTC 2014
| Error java.lang.IllegalStateException: Method on class [com.xxxxxxxx.Detail] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
| Error at com.xxxxxxxx.Detail.currentGormValidationApi(Detail.groovy)
| Error at com.xxxxxxxx.Detail.validate(Detail.groovy)
| Error at com.xxxxxxxx.Detail$validate$2.call(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
| Error at com.apporder.Report$__clinit__closure19_closure21_closure22.doCall(Report.groovy:49)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086)
| Error at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error at groovy.lang.Closure.call(Closure.java:411)
| Error at groovy.lang.Closure.call(Closure.java:427)
| Error at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1325)
| Error at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1297)
| Error at org.codehaus.groovy.runtime.dgm$148.invoke(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
| Error at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
| Error at com.apporder.Report$__clinit__closure19_closure21.doCall(Report.groovy:47)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086)
| Error at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error at groovy.lang.Closure.call(Closure.java:411)
| Error at org.codehaus.groovy.grails.validation.ValidatorConstraint.processValidate(ValidatorConstraint.java:85)
| Error at org.codehaus.groovy.grails.validation.AbstractConstraint.validate(AbstractConstraint.java:107)
| Error at org.codehaus.groovy.grails.validation.ConstrainedProperty.validate(ConstrainedProperty.java:960)
| Error at org.codehaus.groovy.grails.validation.GrailsDomainClassValidator.validatePropertyWithConstraint(GrailsDomainClassValidator.java:209)
| Error at org.codehaus.groovy.grails.validation.GrailsDomainClassValidator.validate(GrailsDomainClassValidator.java:79)
| Error at org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator.validate(HibernateDomainClassValidator.java:66)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:173)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:63)
| Error at org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi.save(HibernateGormInstanceApi.groovy:196)
| Error at com.apporder.Report.save(Report.groovy)
| Error at com.apporder.Report$save$12.call(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
| Error at com.apporder.service.ReportTransactionalService.create(ReportTransactionalService.groovy:718)
| Error at com.apporder.service.ReportTransactionalService$$FastClassBySpringCGLIB$$6fd1cc0d.invoke(<generated>)
| Error at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
| Error at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
| Error at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
| Error at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
| Error at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
| Error at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
| Error at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
| Error at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
| Error at com.apporder.service.ReportTransactionalService$$EnhancerBySpringCGLIB$$8c34825d.create(<generated>)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
| Error at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80)
| Error at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1108)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
| Error at com.apporder.ReportController$_closure15.doCall(ReportController.groovy:325)
| Error at com.apporder.ReportController$_closure15.doCall(ReportController.groovy)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086)
| Error at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
| Error at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error at groovy.lang.Closure.call(Closure.java:411)
| Error at groovy.lang.Closure.call(Closure.java:405)
| Error at com.apporder.ReportController.save(ReportController.groovy)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:154)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:354)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:231)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:197)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:121)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72)
| Error at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
| Error at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:355)
| Error at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
| Error at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
| Error at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
| Error at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
| Error at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
| Error at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
| Error at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
| Error at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:332)
Detail.groovy约束:
class Detail {
static constraints = {
value(nullable: true, validator: { value, detail ->
def ret = true
if (detail.detailType.subType != "calculated") {
if (detail.detailType.required && Utilities.inList(detail.detailType.type, ["text", "string", "boolean",
"number", "numberPunctuation", "phone", "email", "date", "time", "dateTime"]) &&
(value == null || value.trim() == ""))
ret = "default.selection.required.message"
else if (detail.detailType.type == "number" && value != null && value.trim() != "" && !value.isNumber())
ret = "default.mustbenumeric.message"
else if (detail.detailType.required && detail.detailType.type == "refersTo" && detail.refersTo == null)
ret = "default.selection.required.message"
}
//println "validate ${detail.detailType.name} type[${detail.detailType.type}] required[${detail.detailType.required}] value[${value}] refersTo[${detail?.refersTo?.id}]:${ret}"
return ret
})
selection(nullable: true, validator: { selection, detail ->
def ret = true
if (detail?.detailType?.subType == "calculated") return true
if (detail?.detailType?.required && Utilities.inList(detail.detailType.type, ["menu", "selectOne"]) &&
selection == null)
ret = "default.selection.required.message"
//println "validate ${detail.detailType.name} selection[${selection}]:${ret}"
return ret
})
parent(nullable: true)
details(nullable: true)
audioClipId(nullable: true)
refersTo(nullable: true, validator: { selection, detail ->
def ret = true
if (detail.detailType.required && detail.detailType == "refersTo" && detail.refersTo == null) {
ret = "default.selection.required.message"
}
return ret
})
sort(nullable: true)
placeholderReportId(nullable: true)
}
答案 0 :(得分:0)
我有几次这个错误:
当数据源在错误的convention中初始化时(您应该在Datasource.groovy dataSource_example 中使用(注意大字母和下划线),并使用
{{1}}
诊断非常简单:检查数据库中的表是否正确启动