取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为';MyTastTasklet';
我正在开发Spring Boot批处理示例。在本例中,我创建了BatchJPA核心模块,该模块具有实体、JPARepository和DB配置 这个模块作为依赖项添加到另一个Spring模块中,在这个模块中,我添加了与代码相关的特定批处理作业(如自定义存储库等)。我总共有15个批处理作业,我将使用BatchJPA依赖项创建单独的Spring引导项目取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为';MyTastTasklet';,spring,spring-boot,spring-batch,Spring,Spring Boot,Spring Batch,我正在开发Spring Boot批处理示例。在本例中,我创建了BatchJPA核心模块,该模块具有实体、JPARepository和DB配置 这个模块作为依赖项添加到另一个Spring模块中,在这个模块中,我添加了与代码相关的特定批处理作业(如自定义存储库等)。我总共有15个批处理作业,我将使用BatchJPA依赖项创建单独的Spring引导项目 10-08-2018 14:54:11.853 [main] WARN org.springframework.context.support.Cl
10-08-2018 14:54:11.853 [main] WARN org.springframework.context.support.ClassPathXmlApplicationContext.refresh - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyTestTasklet': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' available
10-08-2018 14:54:11.855 [main] INFO org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.logAutoConfigurationReport -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
10-08-2018 14:54:11.919 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report -
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'transactionManager' that could not be found.
Action:
Consider defining a bean named 'transactionManager' in your configuration.
代码如下:
@Service
public class MyTaskTasklet implements Tasklet {
@Autowired
private MyCustomerCustomRepository myCustomerCustomRepository;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
List<MyTest> mydata = myCustomerCustomRepository.getElligibleData();
if (!mydata.isEmpty()) {
System.out.println("XXXXXX = " + mydata.size());
}
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext()
.put("listOfData", mydata);
return RepeatStatus.FINISHED;
}
}
还有另一个文件
main应用程序
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
public class MainApplication implements CommandLineRunner {
@Autowired
private MyJobLauncher jobLauncher;
public static void main(String[] args) {
SpringApplication.run(MyJobLauncher.class, args);
}
@Override
public void run(String... args) throws Exception {
jobLauncher.executeJob();
}
}
MyTestTasklet
是导致问题的文件,如果没有该文件的代码,很难说问题出在哪里。很可能是自动连线问题,具体取决于transactionManager
的功能。MyTestTasklet已经在上面显示过,您还需要什么指导我呢?@enableBackProcessing
应该在您的上下文中添加一个事务管理器,但它似乎没有被考虑,因为您是从XML文件jobs/ABC.XML
加载作业的。我将移动@EnableBatchProcessing
在MainApplication
类上,并使用SpringApplication.run(MainApplication.class,args)运行应用程序代码>而不是SpringApplication.run(MyJobLauncher.class,args)代码>。您可以试试吗?@prateek您没有显示“MyTestTasklet”您显示的是MyTasklet。您的问题是您正在从executeJob
方法中的ABC.xml
加载新的应用程序上下文。此上下文与Spring启动时加载的上下文不同。因此,缺少的事务管理器(以及所有其他服务)应该在该XML文件中定义,除非从该文件导入其他配置类。
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
public class MainApplication implements CommandLineRunner {
@Autowired
private MyJobLauncher jobLauncher;
public static void main(String[] args) {
SpringApplication.run(MyJobLauncher.class, args);
}
@Override
public void run(String... args) throws Exception {
jobLauncher.executeJob();
}
}