2011-06-22 38 views
11

我有一個使用Spring Batch和Spring MVC的應用程序。我能夠將Spring Batch Admin部署爲單獨的戰爭,並將其用於我的應用程序使用的同一個數據庫,儘管我想將它集成到我自己的應用程序中,也可能修改一些視圖。將Spring批處理管理集成到現有應用程序中

有沒有一種簡單的方法來做到這一點,還是我必須把它叉起來,並從那裏?

回答

14

根據thread顯然有一個簡單的方法;

  • web.xml定義的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> 
    
  • 爲resourceService添加替代根appContext:

    <bean id="resourceService" 
    class="org.springframework.batch.admin.web.resources.DefaultResourceService"> 
        <property name="servletPath" value="/batch" /> 
    </bean> 
    
  • 修改standard.ftl春季批次管理員-resources-1.2.0-RELEASE.jar以反映網址:

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

+0

+1你答案鏈接在這裏:http://forum.springsource.org/showthread.php?116685-Spring-Batch-Admin-App-fails-to-create-configuration-bean – opyate

+0

你可以發佈你的pom.xml的細節在哪裏你聲明spring-batch-admin jar文件的依賴關係? – emeraldjava

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> 

applicationContext添加resourceService豆:

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

根據這個問題的答案,'resourceService'定義應該放在META-INF \ spring \ batch \ override'中。 http://stackoverflow.com/questions/23880396/batch-admin-console-dispatcherservlet-using-internalresourceviewresolver-inste – Stewart

3

取而代之的參考彈簧批次管理XML文件是這樣的:

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

你也可以參考你自己的XML文件

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

含somethink這樣的:

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

我有嵌入Spring Batch的管理員到我的應用程序被打包爲一個jar文件。我這樣做是因爲這個應用程序已經存在,我使用J2SE運行它,而不是像Tomcat那樣的servlet容器。此外,我不太喜歡爲批處理作業部署Web服務器/ 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目錄/主/資源/ WEB-INF文件夾的網絡相關CONFIGS和資源)

相關問題