首页 文章

Spring Batch - 没有定义名为'job-configurations'的bean

提问于
浏览
4

我正在使用一个自定义MVC应用程序,它依赖于SPring Batch,如文档中所述,并在此SO问题Integrating Spring Batch Admin into an existing application的帮助下 .

The trouble now is that as the web-app starts to map various URLs to the appropriate controller the job-configurations step bombs out.

2012-06-04 10:17:54,966 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - <Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'>
2012-06-04 10:17:55,512 INFO [org.springframework.ui.freemarker.SpringTemplateLoader] - <SpringTemplateLoader for FreeMarker: using resource loader [WebApplicationContext for namespace 'admin-servlet': startup date [Mon Jun 04 10:17:54 EDT 2012]; parent: Root WebApplicationContext] and template loader path [/WEB-INF/web/]>
2012-06-04 10:17:55,512 INFO [org.springframework.ui.freemarker.SpringTemplateLoader] - <SpringTemplateLoader for FreeMarker: using resource loader [WebApplicationContext for namespace 'admin-servlet': startup date [Mon Jun 04 10:17:54 EDT 2012]; parent: Root WebApplicationContext] and template loader path [classpath:/org/springframework/batch/admin/web/]>
2012-06-04 10:17:55,512 INFO [org.springframework.batch.admin.web.freemarker.HippyFreeMarkerConfigurer] - <ClassTemplateLoader for Spring macros added to FreeMarker configuration>
2012-06-04 10:17:55,528 INFO [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping] - <Mapped URL path [/configuration] onto handler 'configurationHandler'>
2012-06-04 10:17:56,230 INFO [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping] - <Mapped URL path [/job-configuration] onto handler '/job-configuration'>
...
2012-06-04 10:17:56,230 ERROR [org.springframework.web.servlet.DispatcherServlet] - <Context initialization failed>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/job-configuration.json': Cannot resolve reference to bean 'job-configurations' while setting bean property 'requestChannel'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'job-configurations' is defined

有谁遇到过这个?该应用程序依赖于一个简单的 spring 批处理jar,完全孤立地工作,我希望它从该工件中提取任何所需的作业bean .

2 回答

  • 1

    我向一些同事提出了这个问题,而且我认为 spring 批量管理设计中的一个缺陷似乎与许多典型的Spring设计模式相悖 .

    关于包含数据源的解决方案的上下文的依赖 spring 批处理jar "knows too much" . 这个问题在于,在一个体面的Web应用程序中,数据源可以在运行时根据数量或环境变量(环境,数据中心,应用服务器)动态确定,并不像Dave Syer's(Mysql或HSQL)方法那么简单 . 我已经阅读了posts in spring论坛,但他站在这里,接受了对嫌疑人的侮辱..

    如果批处理作业使用多个数据源(即源和目标DB),则会越来越复杂 . 并不像在webapp中加载数据源那么简单,因为所有相关的bean都已经与Dave的HSQL驱动程序DS以及相关的.sql文件和init脚本连接在一起 .

    这导致我基本上覆盖批处理管理jar中的每个与数据源相关的bean,包括jobrepository(预期),jobExplorer,jobService,以及META-INF / spring / batch / override目录中具有不同文件的其他几个bean . 每个文件都利用spring 3.1的Profile命名空间来加载正确的数据源,并注入所有必需的bean .

  • 1

    确保您的web.xml指定了contextConfigLocation,如下所示 .

    <servlet>
    <servlet-name>Batch Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value> 
    classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,
    classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml
    </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    

相关问题