gpt4 book ai didi

java - 出现 No bean nameed 'jobLauncher' available 异常

转载 作者:行者123 更新时间:2023-12-01 19:38:51 25 4
gpt4 key购买 nike

应用程序已启动但出现此异常

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jobLauncher' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at com.hms.ar.batch.job.ARBatchJobApplication.main(ARBatchJobApplication.java:55)

我尝试在资源文件夹下创建 spring.xml 并定义了 JobLauncher bean。仍然遇到同样的异常

我尝试@Autowire这个bean。仍然遇到同样的异常

我的主要方法中的一些代码

public static void main(String[] args) {
savedArgs = args;
String jobName = processParameters(args);
ApplicationContext ctx = configureApplication(new SpringApplicationBuilder()).run(args);
JobLauncher jobLauncher = (JobLauncher) ctx.getBean("jobLauncher");
JobExplorer jobExplorer = (JobExplorer) ctx.getBean("jobExplorer");
Job job = (Job) ctx.getBean(jobName);

}

我预计我的工作会开始,但由于此异常,它没有开始

最佳答案

将 @EnableBatchProcessing 添加到您的配置类之一。

https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html

The @EnableBatchProcessing works similarly to the other @Enable* annotations in the Spring family. In this case, @EnableBatchProcessing provides a base configuration for building batch jobs. Within this base configuration, an instance of StepScope is created in addition to a number of beans made available to be autowired:

  • JobRepository - bean name "jobRepository"
  • JobLauncher - bean name "jobLauncher"
  • JobRegistry - bean name "jobRegistry"
  • PlatformTransactionManager - bean name "transactionManager"
  • JobBuilderFactory - bean name "jobBuilders"
  • StepBuilderFactory - bean name "stepBuilders"

关于java - 出现 No bean nameed 'jobLauncher' available 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56191591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com