0

您好,我正在尝试在春季批处理中运行一项工作,但它给了我这个我不知道如何解决的错误:

`$`  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)

然而,这是我的应用程序上下文。有人可以帮我解决这个错误吗?几句话来描述这项工作的作用,这项工作从数据库中读取一些记录,然后对每条记录(行 * 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>
4

1 回答 1

3

好吧,当启动一个应用程序时,你真的需要一个主类。

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

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

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

于 2013-05-18T10:12:08.440 回答