2015-09-02 74 views
5

試圖將Spring批處理管理員添加到現有的Spring批處理項目。Spring批處理管理員無法替換佔位符'batch.business.schema.script'

我已經更新的web.xml與彈簧批次管理資源和彈簧批次管理經理

我的設置:

的src /主/資源/

我已添加2個屬性文件。圖1是分批 - 缺省 - 性質,這是一個空文件,而另一個是batch-sqlserver.properties均可進行以下內容:

batch.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver batch.jdbc.url=jdbc:sqlserver://xxx.xxx.xxx:1433;DatabaseName=SpringBatch 
batch.jdbc.user=user 
batch.jdbc.password=password 
batch.jdbc.testWhileIdle=false 
batch.jdbc.validationQuery= 
batch.drop.script=/org/springframework/batch/core/schema-drop-sqlserver.sql 
batch.schema.script=/org/springframework/batch/core/schema-sqlserver.sql 
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer 
batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler 
batch.business.schema.script=business-schema-sqlserver.sql 
batch.database.incrementer.parent=columnIncrementerParent 
batch.grid.size=2 
batch.jdbc.pool.size=6 
batch.verify.cursor.position=true 
batch.isolationlevel=ISOLATION_SERIALIZABLE 
batch.table.prefix=BATCH_ 
batch.data.source.init=false 

web應用/ META-INF /彈簧/批次/超馳/,我已經添加了data-source-context.xml內容:

<?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.xsd"> 

     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
       <property name="jndiName"> 
        <value>java:jboss/datasources/springBatchDB</value> 
       </property> 
     </bean> 
</beans> 

這是在JBoss EAP 6.3中運行的。每次我啓動服務器,它給出了這樣的例外:

11:58:36,116 WARN [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 112) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0' defined in null: Could not resolve placeholder 'batch.business.schema.script' in string value "${batch.business.schema.script}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'batch.business.schema.script' in string value "${batch.business.schema.script}" 
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:223) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265) [spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162) [spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) [spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) [spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1] 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4] 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4] 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3591) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4] 
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3798) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4] 
    at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19] 
    at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:59) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19] 
    at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:94) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19] 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_51] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_51] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_51] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51] 
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51] 
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) 
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'batch.business.schema.script' in string value "${batch.business.schema.script}" 
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) [spring-core-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) [spring-core-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer$PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:259) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:204) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitIndexedArgumentValues(BeanDefinitionVisitor.java:150) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:84) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:169) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:169) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitList(BeanDefinitionVisitor.java:228) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:192) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:169) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:208) [spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
    ... 26 more 

我看到batch.business.schema.script是來自:

spring-batch-admin-manager/src/main/resources/META-INF/spring/batch/bootstrap/manager/data-source-context.xml

在那裏也有「$ { batch.schema.script}「,它是從我的batch-sqlserver.properties而不是batch.business.schema.script加載的。

有誰知道爲什麼或有任何建議? 謝謝!

回答

3

我也遇到了這個問題。我沒有一個單獨的覆蓋data-source-context.xml,但我解決了啓動服務器(在我的情況下的tomcat)與JVM選項稱爲環境:

-DENVIRONMENT=postgresql

你的情況,那就是:

-DENVIRONMENT=sqlserver

我的猜測是,Spring Batch的應用程序使用Spring配置文件來選擇要使用的數據庫類型和需要在初次標誌播種的東西。

僅供參考,這裏是從大衛Syer後在此:

http://forum.spring.io/forum/spring-projects/batch/105054-spring-batch-admin-configuration-for-pointing-the-database?p=562140#post562140

對於代用上下文的做法,他說:

或者你可以用覆蓋XML走,只要因爲您將它放在 的正確位置 - 從用戶指南「將您自己的 相同bean定義添加到彈簧XML配置文件中」 META-INF/spring/batch/override「(這是在類路徑中,而不是戰爭 文件META-INF)。在這種情況下,只需重寫名爲 「dataSource」的bean。

所以你有錯誤的地方的文件。您需要將其移動到您的類路徑中的目錄。

0

嘗試覆蓋佔位符屬性,包括您自己的屬性。

我們假設你放在application.properties你的屬性,那麼這將是:

<?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.xsd"> 

    <!-- Use this to set additional properties on beans at run time --> 
    <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>classpath:/org/springframework/batch/admin/bootstrap/batch.properties</value> 
       <value>classpath:batch-default.properties</value> 
       <value>classpath:batch-${ENVIRONMENT:hsql}.properties</value> 
       <value>classpath:application.properties</value> 
      </list> 
     </property> 
     <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> 
     <property name="ignoreResourceNotFound" value="true" /> 
     <property name="ignoreUnresolvablePlaceholders" value="false" /> 
     <property name="order" value="1" /> 
    </bean> 

</beans> 
相關問題