SpringBoot JPA repository always null

Ihavebelowcode
Controller
@RequestMapping("/reminder")
@ResponseBody
publicStringreminder()throwsException{
JobParametersjobParameters=newJobParametersBuilder().addLong("time",System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(job,jobParameters);
return"Done";
}
Config
@Configuration
publicclassBatchConfig{
@Autowired
publicJobBuilderFactoryjobBuilderFactory;
@Autowired
publicStepBuilderFactorystepBuilderFactory;
@Bean
publicJobjob(){//definesajob
returnjobBuilderFactory.get("job")
.incrementer(newRunIdIncrementer())
.flow(step1())
.end()
.build();
}
@Bean
publicStepstep1(){//definesasinglestep
returnstepBuilderFactory.get("step1")
.chunk(1)//importanttobeoneinthiscasetocommitaftereverylineread
.reader(newReader())
.processor(newProcessor())
.writer(newWriter())
.build();
}
}
Reader
@Service
publicclassReaderimplementsItemReader{
privatestaticfinalLoggerlog=LoggerFactory.getLogger(Reader.class);
@Autowired
MercRepositorymercRepository;
@Override
publicAread()throwsException,UnexpectedInputException,ParseException,NonTransientResourceException{
if(mercRepository!=null)
{
System.out.println("notnull");
}else{
System.out.println("null");
}
ListthList=mercRepository.getMer();
System.out.println("thlistsize"+thList.size());
return(Campaign)thList;
}
}
Error
null
2018-02-2210:05:45ERRORo.s.batch.core.step.AbstractStep-Encounteredanerrorexecutingstepstep1injobjob
java.lang.NullPointerException:null
atcom.rh.app.batch.reader.Reader.read(Reader.java:43)
atcom.rh.app.batch.reader.Reader.read(Reader.java:27)
atorg.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91)
atorg.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157)
atorg.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116)
atorg.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
atorg.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
atorg.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
Ihaveaddeda@Servicetoautowiredtherepository,buttheerrorstillexists.Anyadvice?
慕姐8265434
浏览 1283回答 2
2回答
打开App,查看更多内容