2012-09-28 59 views
0

當我定義使用ref屬性一個tasklet,一切都很好:如何將一個tasklet等定義爲嵌套bean?

<step id="unzipFiles_010_014" next="verifyXmlSignatures_010_014"> 
    <tasklet ref="unzipTasklet_010_014" /> 
</step> 

然而,對於某些情況下,我想直接嵌套的bean定義bean,如:

<step id="unzipFiles_010_014" next="verifyXmlSignatures_010_014"> 
    <tasklet> 
     <bean scope="step" class="some.package.UnZipTasklet"> 
      <property name="file" ref="any.file" /> 
     </bean> 
    </tasklet> 
</step> 

現在我收到一個奇怪的錯誤:

cvc-complex-type.2.4.a: Invalid content was found starting with 
element 'bean'. One of '{"http:// 
www.springframework.org/schema/batch":chunk, 
"http://www.springframework.org/schema/ 
batch":transaction-attributes, 
"http://www.springframework.org/schema/batch":no-rollback-exception-classes, 
"http://www.springframework.org/schema/batch":listeners, 
"http://www.springframework.org/schema/ beans":bean, 
"http://www.springframework.org/schema/beans":ref}' is expected. 

這是一個bean,不是嗎?

我定義驗證器(DefaultJobParametersValidator)時,得到了同樣的奇怪的行爲。

回答

0

可能適用於您的batch:namespace。

例如:

<batch:step id="copyToWorkdir" next="concatStrings"> 
    <batch:tasklet> 
     <bean class="your.tasklet.Class" scope="step"> 
      <property name="inFile" value="xxx" /> 
      <property name="outFile" value="xxx" /> 
     </bean> 
    </batch:tasklet> 
</batch:step> 
+0

不幸的不是。該語法對於step和tasklet是有效的,但是對於bean來說是相同的錯誤。 – Andy

0

你也可以做這樣的:

<step id="unzipFiles_010_014" next="verifyXmlSignatures_010_014"> 
    <tasklet ref="unZipTasklet" scope="step"> 
    </tasklet> 
</step> 

與bean像以前一樣:

<bean id="unZipTasklet" class="some.package.UnZipTasklet"> 
    <property name="file" ref="any.file" /> 
</bean> 

但像maxhax說,這只是命名空間問題... 嘗試maxhas與此命名空間配置的示例:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:batch="http://www.springframework.org/schema/batch" 
    xsi:schemaLocation= 
     "http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 
相關問題