2012-09-28 61 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"> 
相关问题