将Spring Batch Admin集成到现有应用程序中

aba*_*ogh 11 spring spring-mvc spring-batch spring-batch-admin

我有一个使用Spring Batch和Spring MVC的应用程序.我能够将Spring Batch Admin作为一个单独的战争部署,并将其用于我的应用程序使用的同一个DB,尽管我想将它集成到我自己的应用程序中,也可能修改一些视图.

有没有一种简单的方法可以做到这一点,还是我必须分叉并从那里开始?

aba*_*ogh 14

根据这个线程显然有一种简单的方法;

  • web.xml以下位置为Batch Admin定义DispatcherServlet :

    <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>
    
    Run Code Online (Sandbox Code Playgroud)
  • 在根appContext中为resourceService添加覆盖:

    <bean id="resourceService"
    class="org.springframework.batch.admin.web.resources.DefaultResourceService">
        <property name="servletPath" value="/batch" />
    </bean> 
    
    Run Code Online (Sandbox Code Playgroud)
  • 修改standard.ftl春季批次管理员资源-1.2.0-RELEASE.jar反映的网址:

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


小智 7

如果您正在使用Spring-batch-admin 1.2.1,则无需修改standard.ftl文件.你应该添加两个servlet-config.xmlwebapp-config.xml文件org/springframework/batch/admin/web/resources.以下是步骤(再次重复):

    <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>
Run Code Online (Sandbox Code Playgroud)

resourceService在你的添加bean applicationContext:

<bean id="resourceService"
class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/batch" />
</bean>
Run Code Online (Sandbox Code Playgroud)