Integrating Spring Batch Admin into an existing application
Asked Answered
L

4

11

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?

Lieb answered 22/6, 2011 at 10:45 Comment(0)
L
14

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>

Lieb answered 24/6, 2011 at 9:50 Comment(2)
+1 Your answer was linked here: forum.springsource.org/…Spectroradiometer
Can you post details of your pom.xml where you declare the dependencies on the spring-batch-admin jar files?Subdued
M
7

If you are using Spring-batch-admin 1.2.1, you don't have to modify standard.ftl file. And you should add both servlet-config.xml and webapp-config.xml files from org/springframework/batch/admin/web/resources. Here are the steps (repeated again):

    <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>

Add resourceService bean in your applicationContext:

<bean id="resourceService"
class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/batch" />
</bean>
Marauding answered 15/6, 2012 at 17:11 Comment(1)
As per the answer to this question, the resourceService definition should go in META-INF\spring\batch\override. #23880896Aretina
G
4

I have embedded Spring Batch admin into my application that is packaged as a jar file. I did this because this app existed already and I run it using J2SE and not in a servlet container like Tomcat. Moreover I did not quite like the idea of having to deploy a web-server/servlet container for batch jobs. The Spring Batch Admin application is a good reference implementation and almost all interfaces may be replaced using custom classes via Spring DI. Moreover all UI was template driven. I therefore extracted the relevant resources and run the console using an embedded Jetty server that my application launches. This, in effect, has flipped the containment from app inside servlet container to servlet container inside app.

Screen shots are here : https://github.com/regunathb/Trooper/wiki/Trooper-Batch-Web-Console

Source, config resources etc are here : https://github.com/regunathb/Trooper/tree/master/batch-core (check the /src/main/resources/WEB-INF folder for web related configs and resources)

Galeiform answered 18/12, 2012 at 4:31 Comment(0)
C
3

Instead of referencing the spring batch admin XML files like this:

<param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml</param-value>

you can also reference your own XML file

<param-value>classpath:eregister-spring-admin-servlet.xml</param-value>

Containing somethink like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<import resource="classpath*:/META-INF/spring/batch/servlet/resources/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/manager/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/override/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/bootstrap/**/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/override/**/*.xml" />

<!-- Override de standard locatie van spring batch admin resources -->
<bean id="resourceService" class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/batch" />
</bean>

<bean id="parameterUnpackerFilter" class="org.springframework.batch.admin.web.filter.ParameterUnpackerFilter">
    <property name="prefix" value="unpack_"/>
    <property name="putEmptyParamsInPath" value="true"/>
</bean>

</beans>
Cq answered 5/12, 2012 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.