首页 文章

使用批处理作业在现有应用程序中进行Spring批处理管理

提问于
浏览
1

我有一个基于maven的spring web应用程序,我还集成了几个 spring 批处理作业 . 现在要监视这些作业,我想将Spring Batch Admin添加到这个应用程序 .

到目前为止我所做的就是这个 . 1.在contextConfigLocation中的web.xml中添加了这个

classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,
classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml
  • 添加了包含以下内容的batch-default.properties文件 .

batch.jdbc.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver batch.jdbc.url = jdbc:sqlserver:// localhost:1433; SelectMethod = cursor; Database = TestMe batch.jdbc.user = aa batch.jdbc.password = AA

batch.database.incrementer.class = org.springframework.jdbc.support.incremente.SqlServerMaxValueIncrementer batch.data.source.init = false batch.business.schema.script = batch.schema.script = batch.drop.script = batch . remote.base.url =

&具有此名称batch-SQLSERVER.properties的文件

batch.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
batch.jdbc.url=jdbc:sqlserver://localhost:1433;SelectMethod=cursor;Database=TestMe
batch.jdbc.user=aa
batch.jdbc.password=aa
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer
batch.data.source.init=false
batch.business.schema.script=
batch.schema.script=
batch.drop.script=
batch.remote.base.url=
  • 已创建作业的我的数据库表 .

我收到以下错误:

[TRACE] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - getProperty("ENVIRONMENT:hsql", String)
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [servletConfigInitParams]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [servletContextInitParams]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [jndiProperties]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [ENVIRONMENT:hsql]
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] JndiPropertySource - JNDI lookup for name [ENVIRONMENT:hsql] threw NamingException with message: Name [ENVIRONMENT:hsql] is not bound in this Context. Unable to find [ENVIRONMENT:hsql].. Returning null.
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [systemProperties]
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [systemEnvironment]
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] SystemEnvironmentPropertySource - PropertySource [systemEnvironment] does not contain 'ENVIRONMENT:hsql'
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] SystemEnvironmentPropertySource - PropertySource [systemEnvironment] does not contain 'ENVIRONMENT:HSQL'
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Could not find key 'ENVIRONMENT:hsql' in any property source. Returning [null]
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - getProperty("ENVIRONMENT", String)
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [servletConfigInitParams]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [servletContextInitParams]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [jndiProperties]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [java:comp/env/ENVIRONMENT]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiLocatorDelegate - Converted JNDI name [java:comp/env/ENVIRONMENT] not found - trying original name [ENVIRONMENT]. javax.naming.NameNotFoundException: Name [ENVIRONMENT] is not bound in this Context. Unable to find [ENVIRONMENT].
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [ENVIRONMENT]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiPropertySource - JNDI lookup for name [ENVIRONMENT] threw NamingException with message: Name [ENVIRONMENT] is not bound in this Context. Unable to find [ENVIRONMENT].. Returning null.
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [systemProperties]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] PropertySourcesPropertyResolver - Found key 'ENVIRONMENT' in [systemProperties] with type [String] and value 'SQLSERVER'
[TRACE] 2015-03-26 12:01:04.306 [localhost-startStop-1] PropertyPlaceholderHelper - Resolved placeholder 'ENVIRONMENT:hsql'
[TRACE] 2015-03-26 12:01:04.316 [localhost-startStop-1] TypeConverterDelegate - Converting String to [boolean] using property editor [org.springframework.beans.propertyeditors.CustomBooleanEditor@59bde227]
[TRACE] 2015-03-26 12:01:04.317 [localhost-startStop-1] TypeConverterDelegate - Converting String to [boolean] using property editor [org.springframework.beans.propertyeditors.CustomBooleanEditor@59bde227]
[TRACE] 2015-03-26 12:01:04.317 [localhost-startStop-1] TypeConverterDelegate - Converting String to [int] using property editor [org.springframework.beans.propertyeditors.CustomNumberEditor@414a9c78]
[DEBUG] 2015-03-26 12:01:04.318 [localhost-startStop-1] DefaultListableBeanFactory - Finished creating instance of bean 'placeholderProperties'
[INFO ] 2015-03-26 12:01:04.319 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [org/springframework/batch/admin/bootstrap/batch.properties]
[INFO ] 2015-03-26 12:01:04.319 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [batch-default.properties]
[INFO ] 2015-03-26 12:01:04.320 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [batch-SQLSERVER.properties]
[ERROR] 2015-03-26 12:01:04.325 [localhost-startStop-1] ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in URL [file:/C:/tomcat-7.0.54/wtpwebapps/testme/WEB-INF/classes/applicationContext-dao.xml]: Could not resolve placeholder 'hibernate.dialect' in string value "
                hibernate.dialect=${hibernate.dialect}
                hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
                hibernate.show_sql=${hibernate.show_sql}
                hibernate.format.sql=${hibernate.format.sql}
                hibernate.query.substitutions=${hibernate.query.substitutions}
            "
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) [catalina.jar:7.0.54]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) [catalina.jar:7.0.54]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.54]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.54]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.54]
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_71]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_71]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_71]
    at java.lang.Thread.run(Thread.java:745) [?:1.7.0_71]
Mar 26, 2015 12:01:04 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in URL [file:/C:/tomcat-7.0.54/wtpwebapps/testme/WEB-INF/classes/applicationContext-dao.xml]: Could not resolve placeholder 'hibernate.dialect' in string value "
                hibernate.dialect=${hibernate.dialect}
                hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
                hibernate.show_sql=${hibernate.show_sql}
                hibernate.format.sql=${hibernate.format.sql}
                hibernate.query.substitutions=${hibernate.query.substitutions}
            "
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

关于我的要求我需要能够使用Spring批处理管理员监视当前应用程序中的作业 .

感谢您查看它 . 我确实按照网站上的文档 . 我还参考了动作书中 Spring 天的代码 . 我正在使用 spring 批次的版本1.3.0.RELEASE与 spring 3.2.0.RELEASE . 从堆栈跟踪本身我可以说问题是没有正确读取属性 . 但如果我删除这些文件/配置我的应用程序工作正常 . 我正在传递-DEVIRONMENT =“SQLSERVER”作为运行时争论 . 请提供您的意见 .

我在SO上提到了这个问题:Integrating Spring Batch Admin in existing application.

1 回答

  • 1

    我在这个question回答了类似的问题 . 当您集成spring batch admin和spring batch应用程序时,从spring batch admin中选择属性资源加载配置 . 您需要覆盖它以包含spring boot通常保存配置文件的位置 .

    我还在那里添加了评论,我们开始采用类似的方法,将单个 spring 启动应用程序与 spring 批处理作业和 spring 批处理管理进行监视,这被证明是整合的痛苦,我们使其工作但我们必须配置所有方面比如果它只是 Spring 季批量应用程序 . 你不能使用java配置,只有xml和很多事情发生冲突(当你添加 @EnableScheduling 注释使用spring schedulers时,一些spring batch beans开始被调度等)

    我们最终得到了两个应用程序,一个用于保存作业并且只有 Spring 季批处理,另一个应用程序在我们仅用于监视的同一个mysql DB之上具有spring batch admin . 您通过UI和Spring批处理管理员休息来放松触发作业,但我们通过消息队列触发作业,因此我们只需要监控,这对我们来说是一个很好的解决方案 .

相关问题