【问题标题】:Integrating Spring Batch Admin into an existing application将 Spring Batch Admin 集成到现有应用程序中
【发布时间】:2011-06-22 10:45:15
【问题描述】:

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

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

【问题讨论】:

    标签: spring spring-mvc spring-batch spring-batch-admin


    【解决方案1】:

    显然根据这个thread有一个简单的方法;

    • 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>
      
    • 在根 appContext 中为 resourceService 添加一个覆盖:

      <bean id="resourceService"
      class="org.springframework.batch.admin.web.resources.DefaultResourceService">
          <property name="servletPath" value="/batch" />
      </bean> 
      
    • 修改 spring-batch-admin-resources-1.2.0-RELEASE.jar 中的 standard.ftl 以反映 URL:

      &lt;#assign url&gt;&lt;@spring.url relativeUrl="${servletPath}/resources/styles/main.css"/&gt;&lt;/#assign&gt;

    【讨论】:

    • +1 你的答案链接在这里:forum.springsource.org/…
    • 您能否发布您的 pom.xml 的详细信息,在其中声明对 spring-batch-admin jar 文件的依赖关系?
    【解决方案2】:

    如果您使用Spring-batch-admin 1.2.1,则不必修改standard.ftl 文件。您应该同时添加来自org/springframework/batch/admin/web/resourcesservlet-config.xmlwebapp-config.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,classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    

    在您的applicationContext 中添加resourceService bean:

    <bean id="resourceService"
    class="org.springframework.batch.admin.web.resources.DefaultResourceService">
        <property name="servletPath" value="/batch" />
    </bean>
    

    【讨论】:

    【解决方案3】:

    我已将 Spring Batch admin 嵌入到打包为 jar 文件的应用程序中。我这样做是因为这个应用程序已经存在并且我使用 J2SE 运行它,而不是在像 Tomcat 这样的 servlet 容器中。此外,我不太喜欢必须为批处理作业部署 web-server/servlet 容器的想法。 Spring Batch Admin 应用程序是一个很好的参考实现,几乎所有接口都可以通过 Spring DI 使用自定义类替换。此外,所有 UI 都是模板驱动的。 因此,我提取了相关资源并使用我的应用程序启动的嵌入式 Jetty 服务器运行控制台。实际上,这已经将容器从 servlet 容器内的应用程序翻转到应用程序内的 servlet 容器。

    屏幕截图在这里:https://github.com/regunathb/Trooper/wiki/Trooper-Batch-Web-Console

    源、配置资源等在这里:https://github.com/regunathb/Trooper/tree/master/batch-core(检查 /src/main/resources/WEB-INF 文件夹以获取与 Web 相关的配置和资源)

    【讨论】:

      【解决方案4】:

      而不是像这样引用 spring 批处理管理 XML 文件:

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

      您也可以引用自己的 XML 文件

      &lt;param-value&gt;classpath:eregister-spring-admin-servlet.xml&lt;/param-value&gt;

      包含这样的想法:

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

      【讨论】:

        猜你喜欢
        • 2011-10-16
        • 2018-05-26
        • 2019-05-26
        • 2010-10-27
        • 2016-11-18
        • 2015-02-27
        • 1970-01-01
        • 2012-08-07
        • 2018-12-09
        相关资源
        最近更新 更多