我越来越:
BeanInitializationException: Property 'job' is required for bean 'jobScheduler'
即使我有一个正确定义的“batch:job”bean,并且我有一个指向它的属性声明,如下所示:
<batch:job id="userSummary">
...
</batch:job>
<bean id="jobScheduler" class="cc.glance.server.business.fact.JobScheduler">
<property name="job" ref="userSummary" />
</bean>
注意:“userSummary”的定义应该没有问题,因为它之前工作得很好,当我通过 Web 控制器而不是调度调用它时。
堆栈跟踪:
2014-05-14 11:54:08,022 | ERROR | ion(5)-127.0.0.1 | o.a.c.c.C.[.[.[/] | apache.juli.logging.DirectJDKLog 185 | Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobScheduler' defined in URL [jar:file:/C:/VICTOR/TRABALHO/glance/glance-core/server/glance-server-webapp/target/glance-server-webapp-2.2.2-SNAPSHOT/WEB-INF/lib/glance-server-business-2.2.2-SNAPSHOT.jar!/cc/glance/server/business/fact/JobScheduler.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'job' is required for bean 'jobScheduler'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) [catalina.jar:7.0.53]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) [catalina.jar:7.0.53]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:7.0.53]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) ~[catalina.jar:7.0.53]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) ~[catalina.jar:7.0.53]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) ~[catalina.jar:7.0.53]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1740) ~[catalina.jar:7.0.53]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) ~[tomcat-coyote.jar:7.0.53]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[na:1.7.0_25]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:1.7.0_25]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618) ~[catalina.jar:7.0.53]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565) ~[catalina.jar:7.0.53]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) ~[tomcat-coyote.jar:7.0.53]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[na:1.7.0_25]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:1.7.0_25]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) ~[na:1.7.0_25]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) ~[na:1.7.0_25]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) ~[na:1.7.0_25]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420) ~[na:1.7.0_25]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) ~[na:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) ~[na:1.7.0_25]
at sun.rmi.transport.Transport$1.run(Transport.java:177) ~[na:1.7.0_25]
at sun.rmi.transport.Transport$1.run(Transport.java:174) ~[na:1.7.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_25]
at sun.rmi.transport.Transport.serviceCall(Transport.java:173) ~[na:1.7.0_25]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) ~[na:1.7.0_25]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) ~[na:1.7.0_25]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: org.springframework.beans.factory.BeanInitializationException: Property 'job' is required for bean 'jobScheduler'
at org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.postProcessPropertyValues(RequiredAnnotationBeanPostProcessor.java:156) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.0.RELEASE.jar:4.0.0.RELEASE]
... 54 common frames omitted
JobScheduler 类:
@Component
public class JobScheduler
{
@Autowired
private JobLauncher jobLauncher;
private Job job;
private final Logger logger = LoggerFactory.getLogger(getClass());
@Required
public void setJob(Job job)
{
this.job = job;
}
public void run()
{
try
{
Date endDate = new Date();
Date beginDate = DateUtils.addWeeks(endDate, -1);
String summaryId = beginDate.toString(); //TODO proper summaryId
JobParametersBuilder builder = new JobParametersBuilder();
builder.addDate("dateFrom", beginDate);
builder.addDate("dateTo", endDate);
builder.addString("summaryId", summaryId);
JobParameters param = builder.toJobParameters();
JobExecution execution = jobLauncher.run(job, param);
logger.info("Exited UserSummary job scheduling with status: " + execution.getStatus());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}