这个运行错误意味着什么?

时间:2013-05-18 07:52:52

标签: spring spring-batch

你好,我试图在春季批次中运行一份工作,但它给了我这个错误,我不知道如何解决:

`$`  C:\Program Files\Microsoft Visual Studio 8\VC>java -jar C:\Workspacetest\testpro
    ject\target\ams-eod-0.0.1-SNAPSHOT.jar copyJob 1 `$`

Exception in thread "main" java.lang.NullPointerException
    at sun.launcher.LauncherHelper.getMainClassFromJar(LauncherHelper.java:399)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:463)

然而,这是我的applicationcontext。有人可以帮我解决这个错误吗? 用几句话来描述这项工作的作用,这项工作从数据库中读取一些记录,然后对每条记录进行计算(行* 3.75),然后更新记录。

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/batch" 
     xmlns:beans="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
           http://www.springframework.org/schema/batch 
           http://www.springframework.org/schema/batch/spring-batch-2.2.xsd">

<beans:bean id="itemReader" class="org.spr...JdbcCursorItemReader">
    <beans:property name="dataSource" ref="dataSource"/>
    <beans:property name="sql" value="select * from Trans WHERE id =?"/>
    <beans:property name="rowMapper" ref= "CustomerCreditRowMapper"/>
    <beans:property name="preparedStatementSetter" ref="idSetter"/>
</beans:bean>

<beans:bean id="transactionProcessor" class="">
    <beans:property name="targetObject" ref="Processing"/>
    <beans:property name="targetMethod" value="process"/>
</beans:bean>

<beans:bean id="jdbcWriter"                                
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
        <beans:property name="dataSource" ref="dataSource"/> 
    <beans:property name="sql" value="update Trans set (amount) values (?)"/>
    <beans:property name="preparedStatementSetter" ref="idSetter"/>
</beans:bean> 

<step id="CopyFileStep">
    <tasklet>
        <chunk reader="itemReader"
               processor="transactionProcessor"
               writer="jdbcWriter"
               commit-interval="10"/>
    </tasklet>
</step>

<job id="copyJob">
    <step id="step1" parent="CopyFileStep"/>
</job>

<beans:bean id="preparedStatementSetter"   
class="sa.com.anb.itg.dev.settlement.batch.Itemwriter"/>

<beans:bean id="idSetter" class="sa.com.anb.itg.dev.settlement.batch.idSetter"    
scope="step">
    <beans:property name="id" value="#{jobParameters[id]}"/>
</beans:bean>

<beans:bean id="CustomerCreditRowMapper"     
class="sa.com.anb.itg.dev.settlement.batch.CustomerCreditRowMapper"/>

<beans:bean id="AmountToTransactionItemProcessor" 
    class="sa.com.anb.itg.dev.settlement.batch.AmountToTransactionItemProcessor">
        <beans:property name="TransactionDAO" ref="TransactionDAO"/>
</beans:bean>

<beans:bean id="TransactionDAO" class="sa.com.anb.itg.dev.settlement.batch.TransactionDAO">
    <beans:property name="datasource" ref="dataSource"/>
</beans:bean>       

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
   <beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
   <beans:property name="url" value="jdbc:oracle:thin:@192.168.84.208:1556:pay10g" />
   <beans:property name="username" value="ams_recon" />
   <beans:property name="password" value="ams_recon" />
</beans:bean>

<beans:bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
            <beans:property name="dataSource" ref="dataSource"/>
            <beans:property name="transactionManager" ref="transactionManager"/>
</beans:bean>

<beans:bean id="jobLauncher"
  class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <beans:property name="jobRepository" ref="jobRepository" />
</beans:bean>

<beans:bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
    <beans:property name="dataSource" ref="dataSource"/>
</beans:bean>

</beans:beans>

1 个答案:

答案 0 :(得分:3)

好吧,在推出应用程序时,你真的需要一个主类。

Spring Batch可以为您提供一个:CommandLineJobRunner。

在您的示例中,您似乎正尝试使用commandLine执行您的应用程序,就像常规应用程序一样。这里Java试图找到你的Manifest文件,因为JVM需要一个Main类,它无法在你的JAR中找到它导致你的错误。

您必须使用命令行启动它的应用程序,它是CommandLineJobRunner,它提供了一个能够启动批处理的Main方法。 文档说明了如何使用它:http://static.springsource.org/spring-batch/reference/html/configureJob.html#runningJobsFromCommandLine