我使用预定作业经常检索许可证。当我检索每个许可证的许可证时,我想将该许可证添加到每个帐户的哈希映射。在hashmap中,我有一个帐户和一个许可证列表。对于每个许可证,我尝试检查哈希映射中是否已有许可证列表,如果我没有创建新列表并且工作正常。但是如果有一个列表,我会尝试将其添加到该列表中,并且由于某种原因它会抛出错误
licenses.each{license->
List<License> licensesPerAccount = accountLicenseMap.get(license.account)
log.info("initial licenseperaccount " + licensesPerAccount)
if(licensesPerAccount == null) {
accountLicenseMap.put(license.account, license as List<License>)
} else{
log.info("licenseperaccount in else is " + licensesPerAccount)
licensesPerAccount.push(license)
log.info("licenseperaccount now is " + licensesPerAccount)
accountLicenseMap.put(license.account, licensesPerAccount)
}
}
这是它抛出的错误:
ERROR 2017-12-27 10:12:59,045 grails.plugins.quartz.listeners.ExceptionPrinterJobListener - 作业中发生异常:Grails Job org.quartz.JobExecutionException:groovy.lang.MissingMethodException:没有方法签名:com.x.License.add()适用于参数类型:(com.x.License)值:[com.x.License:10] 可能的解决方案:any(),find(com.x.License),any(groovy.lang.Closure),wait(),last(),save() at grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:111) 在org.quartz.core.JobRunShell.run(JobRunShell.java:202) 在org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573) 引起:groovy.lang.MissingMethodException:没有方法签名:com.x.License.add()适用于参数类型:(com.x.License)值:[com.x.License:10] 可能的解决方案:any(),find(com.x.License),any(groovy.lang.Closure),wait(),last(),save() 在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) 在org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite $ PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:253) 在org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) 在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 在com.x.NewLicenseJob $ _execute_closure1 $$ EQezpeTI.doCall(NewLicenseJob.groovy:32) at sun.reflect.GeneratedMethodAccessor629.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497) at org.springsource.loaded.ri.ReloadedTypeInvoker $ 2.invoke(ReloadedTypeInvoker.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461) 在org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 在org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) 在groovy.lang.Closure.call(Closure.java:426) 在com.x.NewLicenseJob $ _execute_closure1.call(NewLicenseJob.groovy) 在groovy.lang.Closure.call(Closure.java:442) 在com.x.NewLicenseJob $ _execute_closure1.call(NewLicenseJob.groovy) 在org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2030) 在org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2015) 在org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2056) 在org.codehaus.groovy.runtime.dgm $ 162.invoke(未知来源) 在org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite $ PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274) 在org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) 在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 在com.x.NewLicenseJob $$ EQezpeT2.execute(NewLicenseJob.groovy:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497) at org.springsource.loaded.ri.ReloadedTypeInvoker $ 2.invoke(ReloadedTypeInvoker.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461) at grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:104) ...省略了2个常见帧
这就是它记录的内容:
INFO 2017-12-27 10:12:59,029 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount null 休眠:选择account0_.id为id1_4_0_,account0_.approve_hours_by_manager为approve_2_4_0_,account0_.brand_id为brand_id3_4_0_,account0_.check_tags为check_ta4_4_0_,account0_.checkin_at_work_module为checkin_5_4_0_,account0_.cj1_export为cj6_4_0_,account0_.company_id为company_7_4_0_,account0_.csv_import为csv_impo8_4_0_ ,account0_.default_date_pattern如default_9_4_0_,account0_.default_date_time_pattern如default10_4_0_,account0_.default_time_pattern如default11_4_0_,account0_.default_time_zone如default12_4_0_,account0_.default_view如default13_4_0_,account0_.deleted如deleted14_4_0_,account0_.display_as_decimal如display15_4_0_,account0_.instant_feedback如instant16_4_0_,account0_ .language as languag17_4_0_,account0_.match_registration_hours as match_r18_4_0_,account0_.payroll_hours as payroll19_4_0_,account0_.project_tags as project20_4_0_,account0_.separate_date as separat21_4_0_,account0_.show_charts as show_ch22_4_0_,account0_.templa_link as templa_23_4_0_,account0_.vip_export as vip_exp24_4_0_来自account account0_ where account0_.id =? Hibernate:选择company0_.id为id1_14_0_,company0_.account_id为account_2_14_0_,company0_.address为address3_14_0_,company0_.city为city4_14_0_,company0_.cocnumber为cocnumbe5_14_0_,company0_.country为country6_14_0_,company0_.deleted为deleted7_14_0_,company0_.emailaddress为emailadd8_14_0_ ,company0_.logo_url如logo_url9_14_0_,company0 _
name
如name10_14_0_,company0_.phonenumber如phonenu11_14_0_,company0_.province如provinc12_14_0_,company0_.vatnumber如vatnumb13_14_0_,company0_.website如website14_14_0_,company0_.zipcode从公司company0_其中zipcode15_14_0_ company0_.id =? INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - 初始licenseperaccount null INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - 初始licenseperaccount [com.x.License:9] INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - licenseperaccount in else is [com.x.License:9]
答案 0 :(得分:0)
我通过创建列表修复了它,如下所示:
List<License> licenseList = []
licenseList << license
accountLicenseMap.put(license.account, licenseList)
而不是accountLicenseMap.put(license.account, license as List<License>)