网站短信通知,阜宁做网站哪家公司最好,电子商务网站建设计划,环保网站 怎么做我有一个小的示例Spring Batch应用程序#xff0c;该应用程序在首次启动时可以正常运行#xff0c;但是每当我关闭该应用程序并重新启动jar时#xff0c;我总是会收到此错误#xff1a;Caused by: org.springframework.dao.DuplicateKeyException: PreparedStatementCallba…我有一个小的示例Spring Batch应用程序该应用程序在首次启动时可以正常运行但是每当我关闭该应用程序并重新启动jar时我总是会收到此错误Caused by: org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Duplicate entry 1 for key 1; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 1 for key 1我不确定作业增量器设置是否错误。但是就像我说的那样我可以启动它然后使用Web服务url/jobLauncher.html任意次调用批处理。只有在我关闭应用程序并重新启动它之后我才收到此错误。它想为作业执行表使用ID1但以前的运行中已经有ID 1。主班EnableAutoConfigurationComponentScanpublic class Application {public static void main(String[] args) throws Exception {SpringApplication.run(Application.class, new String[]{ date System.currentTimeMillis() });}}Web服务类Controllerpublic class JobLauncherController {AutowiredJobLauncher jobLauncher;AutowiredJob job;RequestMapping(/jobLauncher.html)ResponseBodypublic String handle() throws Exception{jobLauncher.run(job, new JobParametersBuilder().addString(date, System.currentTimeMillis() ).toJobParameters());return Started the batch...;}}Spring批处理类ConfigurationEnableBatchProcessingpublic class SampleBatchApplication {Autowiredprivate JobBuilderFactory jobs;Autowiredprivate StepBuilderFactory steps;Beanprotected Tasklet tasklet() {return new Tasklet() {Overridepublic RepeatStatus execute(StepContribution contribution,ChunkContext context) {return RepeatStatus.FINISHED;}};}Beanpublic Job job() throws Exception {return this.jobs.get(job).incrementer(new RunIdIncrementer()).flow(this.step1()).end().build();}Beanprotected Step step1() throws Exception {return this.steps.get(step1).tasklet(this.tasklet()).build();}Beanpublic DataSource dataSource() {BasicDataSource ds new BasicDataSource();try {ds.setDriverClassName(com.mysql.jdbc.Driver);ds.setUsername(test);ds.setPassword(test);ds.setUrl(jdbc:mysql://127.0.0.1:3306/spring-batch);} catch (Exception e) {e.printStackTrace();}return ds;}}