我正在为Grails 2.2.3应用程序添加功能,我有以下两项服务:
abstract class AbstractProcessService {
def grailsApplication
ConfigObject getConfig() {
return grailsApplication.config.processes
}
}
class PhotoMoverService extends AbstractProcessService {
void processPhotos() {
// Method body
}
private ConfigObject getPhotoConfig() {
config.photoMover
}
}
当Quartz作业最终运行processPhotos()
PhotoMoverService
方法时,会发生以下错误:
core.ErrorLogger An error occured instantiating job to be executed. job= 'Photo Processes.com.company.processes.PhotoMoverJob'
org.quartz.SchedulerException: Job instantiation failed [See nested exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.processes.PhotoMoverJob': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoMoverService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.codehaus.groovy.grails.commons.AbstractGrailsClass.newInstance()] threw exception; nested exception is org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!]
at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.processes.PhotoMoverJob': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoMoverService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.codehaus.groovy.grails.commons.AbstractGrailsClass.newInstance()] threw exception; nested exception is org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!
at grails.plugins.quartz.GrailsJobFactory.createJobInstance(GrailsJobFactory.java:48)
at grails.plugins.quartz.QuartzMonitorJobFactory.createJobInstance(QuartzMonitorJobFactory.groovy:22)
... 2 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoMoverService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.codehaus.groovy.grails.commons.AbstractGrailsClass.newInstance()] threw exception; nested exception is org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.codehaus.groovy.grails.commons.AbstractGrailsClass.newInstance()] threw exception; nested exception is org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!
... 4 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.codehaus.groovy.grails.commons.AbstractGrailsClass.newInstance()] threw exception; nested exception is org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!
... 4 more
Caused by: org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.company.processes.PhotoMoverService]!
... 4 more
Caused by: java.lang.NullPointerException: Cannot get property 'config' on null object
at com.company.processes.AbstractProcessService.getConfig(AbstractProcessService.groovy:23)
at com.company.processes.PhotoMoverService.getPhotoConfig(PhotoMoverService.groovy:213)
... 4 more
当我调试应用程序时,grailsApplication
中的AbstractProcessService
为空,就像没有正确注入一样。任何人都可以告诉我 1)为什么没有注射, 2)我能做些什么来实现这一目标。谢谢!