0

我越来越:

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();
        }
    }
}
4

2 回答 2

0

正如@AndreiStefan 所建议的,问题在于如何加载spring XML 文件。

我在这里复制的 XML(带有“userSummary”作业和“jobScheduler”bean)没有被加载。它只是从另一个 XML 中引用,将其设置为“AutomaticJobRegistrar”,扫描它以查找作业(仅作业,没有其他 bean)。这就是为什么它在我的网络控制器上工作的原因,正如我在问题中指出的那样。现在我定义的“jobScheduler”bean 没有工作,所以它没有按照我想要的属性集加载。

现在我将我的 JobScheduler 类注释为@Component。这就是为什么上下文仍然加载它,尽管没有所需的属性,从而引发异常。

为了解决这个问题,我将“jobScheduler”定义移到了上下文正在加载的另一个 XML 中(它位于由 applicationContext.xml 的导入引用的文件夹上)。

于 2014-05-14T21:06:51.320 回答
0

回答与@Vituel 类似的问题。更具体地说,我既加载了 XML 文件中定义的 bean,又将其指定为@Component. 即使我适当地定义了属性,它们也是按要求出现的,而不是指定的:

<bean id="newMappingFileController" class="...NewMappingFileController">
    <property name="sasMappingBO" ref="sasMappingBO" />
</bean>
...
Error...
Caused by: ...BeanInitializationException: Property 'sasMappingBO' is required...

我的解决方案只是@Component从课堂上删除注释并且一切正常。

于 2015-07-15T16:07:44.387 回答