Integrating Spring Batch Admin into an existing application

abalogh picture abalogh · Jun 22, 2011 · Viewed 18.4k times · Source

I have an application which uses Spring Batch and Spring MVC. I am able to deploy Spring Batch Admin as a separate war and use it against the same DB my application uses, though I would like to integrate it into my own application, possibly modify some of the views as well.

Is there an easy way to do this or do I have to fork it and go from there?

Answer

abalogh picture abalogh · Jun 24, 2011

There is an easy way apparently according to this thread;

  • Define a DispatcherServlet for Batch Admin in web.xml:

    <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</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>Batch Servlet</servlet-name>
        <url-pattern>/batch/*</url-pattern>
    </servlet-mapping>
    
  • Add an override for resourceService in the root appContext:

    <bean id="resourceService"
    class="org.springframework.batch.admin.web.resources.DefaultResourceService">
        <property name="servletPath" value="/batch" />
    </bean> 
    
  • Modify standard.ftl in spring-batch-admin-resources-1.2.0-RELEASE.jar to reflect the URL:

    <#assign url><@spring.url relativeUrl="${servletPath}/resources/styles/main.css"/></#assign>