如何从 Spring Batch Tasklet 调用存储过程?

问题描述 投票:0回答:1

提到Spring Batch中的TaskletStep可以用来调用存储过程。谁能提供一个如何从 TaskletStep 调用存储过程的示例?到目前为止,我已经做到了这一点,但它抛出一个异常,说“配置问题:元素 [callStoredProcedure] 无法访问”

       <job id="job1">
          <step id="step1">
                <tasklet ref="myTasklet"/>
          </step>
       </job>

       <bean id="myTasklet" class="MyClass">
             <property name="dataSource" ref="dataSource"/>
             <property name="sql" value="call stored_procedure()"/>
       </bean>

Java 类

        class MyClass implements Tasklet{
               @Override
               public RepeatStatus execute(StepContribution contribution,
        ChunkContext chunkContext) throws Exception {
                  JdbcTemplate myJDBC=new JdbcTemplate(getDataSource());
                  myJDBC.execute(sql);
                  return RepeatStatus.FINISHED;
             }      
        }
                

存储过程应该如何配置以及在哪里配置?如果能收到任何指点,我将不胜感激?

spring spring-batch
1个回答
0
投票

而不是

value="call stored_procedure()"

就放

value="stored_procedure"

末尾没有 ()。这应该可以解决您的问题

© www.soinside.com 2019 - 2024. All rights reserved.