2013-05-18 29 views
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) 

但是這是我的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> 
+0

您控制該應用程序的代碼,對不對? – acdcjunior

+0

是的,我確實控制了應用程序。 – user1744446

+0

粘貼'main()'方法的代碼。此外,它是一個最常用的類的摘錄。 – acdcjunior

回答

3

那麼,啓動一個應用程序時,你真的需要一個主類。

Spring Batch可以爲您提供一個:CommandLineJobRunner。

在你的例子中,你似乎試圖像使用commandLine一樣執行你的應用程序。在這裏,Java試圖找到你的Manifest文件,因爲JVM需要一個Main類,它不能在你的JAR中找到它,從而導致你的錯誤。

這不是您的應用程序,您必須使用命令行啓動它,它是CommandLineJobRunner,它提供了一個可以啓動您的批處理的Main方法。 該文檔顯示如何使用它:http://static.springsource.org/spring-batch/reference/html/configureJob.html#runningJobsFromCommandLine

+0

沒有我沒有,但基於我讀過什麼,我不需要有一個主要的類,因爲我要運行它在CommandLineJobRunner。我不確定,因爲我是春季新人。請提供給我一個樣本主類是可能的。我會非常感激。 – user1744446

+0

我編輯了我的答案。 –

+0

非常感謝你,這非常有幫助,但主要課程不在那裏,我正在尋找被刪除。任何提示如果可能的話 – user1744446

相關問題