我在应用程序启动时启动一个 spring-batch
作业
spring.batch.job.names=MyJob
@Configuration
public class MyJob {
@Bean
public Job testJob() throws IOException {
return jobBuilderFactory.get(MyJob.class.getSimpleName())
.start(import())
.build();
}
}
不幸的是,这会以某种方式延迟 tomcat
服务器启动。该作业有几分钟的运行时间,因此我收到以下错误:
Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.
问题:如何在不阻止 tomcat 启动的情况下运行此作业?例如运行异步作业?
最佳答案
您可以包含 ServletContextListener .
将您的代码放在 contextInitialized 中方法。
关于java - 如何在 tomcat 服务器启动时运行长时间运行的批处理作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34656257/