Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Spring批处理管理集成到现有应用程序中_Spring_Spring Mvc_Spring Batch_Spring Batch Admin - Fatal编程技术网

将Spring批处理管理集成到现有应用程序中

将Spring批处理管理集成到现有应用程序中,spring,spring-mvc,spring-batch,spring-batch-admin,Spring,Spring Mvc,Spring Batch,Spring Batch Admin,我有一个使用SpringBatch和SpringMVC的应用程序。我能够将Spring Batch Admin作为一个单独的war部署,并针对我的应用程序使用的同一个DB使用它,尽管我希望将它集成到我自己的应用程序中,也可能修改一些视图 有没有一个简单的方法可以做到这一点,或者我必须用叉子叉起来,然后从那里走下去?显然,根据这一点,有一个简单的方法 在web.xml中为批处理管理定义DispatcherServlet: <servlet> <servlet-name&

我有一个使用SpringBatch和SpringMVC的应用程序。我能够将Spring Batch Admin作为一个单独的war部署,并针对我的应用程序使用的同一个DB使用它,尽管我希望将它集成到我自己的应用程序中,也可能修改一些视图


有没有一个简单的方法可以做到这一点,或者我必须用叉子叉起来,然后从那里走下去?

显然,根据这一点,有一个简单的方法

  • 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>
    
    
    批处理Servlet
    org.springframework.web.servlet.DispatcherServlet
    上下文配置位置
    classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml
    1.
    批处理Servlet
    /批处理/*
    
  • 在根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:


如果您使用的是
Spring batch admin 1.2.1
,则不必修改
standard.ftl
文件。您应该从
org/springframework/batch/admin/web/resources
添加
servlet config.xml
webapp config.xml
文件。以下是步骤(再次重复):


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

<param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml</param-value>
<?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>
classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml
您还可以引用自己的XML文件

classpath:eregister spring admin servlet.xml

包含这样的想法:

<param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml</param-value>
<?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>

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

屏幕截图如下:


Source、config resources等在这里:(检查/src/main/resources/WEB-INF文件夹中与WEB相关的配置和资源)

+1您的答案链接在这里:您可以发布pom.xml的详细信息,在那里声明对spring batch admin jar文件的依赖关系吗?根据这个问题的答案,
resourceService
定义应该放在
META-INF\spring\batch\override
中。