Frage

I am using a custom MVC application that has dependencies on SPring Batch as described in their documentation, and assisted by this SO question 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

Anyone encounter this? The app has a dependencies on a simple spring-batch jar that works fully in isolation, and i would expect it to pull any needed job beans from that artifact.

War es hilfreich?

Lösung

I raised this question up to some of my colleagues, and it seems to be what I would consider a flaw in the design of spring batch admin that goes against many typical Spring design patterns.

The dependent spring batch admin jar "knows too much" about the context of the solution including the datasource. The problem with this is that in a decent web-app, the datasource may be dynamically determined at run time based on a number or environmental variables (environment, datacenter, app server) and is not as simple as Dave Syer's (Mysql or HSQL) approach. I have read posts in spring forum where he stands by this however, bordering insults to the questionee..

It is increasingly complicated if your batch job uses multiple datasources (i.e. source and destination DBs). And was not as simple as just loading a datasource in the webapp, because all the related beans were already wired with Dave's HSQL driver DS, and related .sql files and init scripts.

And this led to me to override essentially every datasource related bean from the batch admin jar, including jobrepository (expected), jobExplorer, jobService, and a few others with a distinct file in the META-INF/spring/batch/override directory. Each file leverages spring 3.1's Profile namespace to load the proper datasource, and inject to all the required beans.

Andere Tipps

Make sure your web.xml specifies contextConfigLocation as below.

<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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top