Java 使用Spring Integration JAR时,Spring批处理未退出

Java 使用Spring Integration JAR时,Spring批处理未退出,java,spring,spring-boot,spring-integration,spring-batch,Java,Spring,Spring Boot,Spring Integration,Spring Batch,当我使用SpringIntegrationJAR时,我的Spring应用程序并没有退出。MBeanExporter没有注销bean并关闭 以下是日志: 无罐 用罐子 带系统。退出(0) 使用context.stop() 弹簧发射器类 添加System.exit(0)和ctx.stop()后,我更新了日志。context.stop()没有像System.exit(0)那样关闭所有组件。当我使用ctx.stop()时,线程仍在运行。当您使用Spring集成时,它会创建几个活动组件作为基础结构bean

当我使用SpringIntegrationJAR时,我的Spring应用程序并没有退出。MBeanExporter没有注销bean并关闭

以下是日志:

无罐 用罐子 带系统。退出(0) 使用context.stop() 弹簧发射器类
添加
System.exit(0)
ctx.stop()后,我更新了日志。
context.stop()
没有像
System.exit(0)
那样关闭所有组件。当我使用
ctx.stop()

时,线程仍在运行。当您使用Spring集成时,它会创建几个活动组件作为基础结构bean,以支持应用程序上下文中的其他bean。其中一个是
ThreadPoolTaskExecutor

要正确关闭带有活动组件的应用程序上下文,您需要使用
ConfigurableApplicationContext.close()

/**
*关闭此应用程序上下文,释放
*实施可能会成功。这包括销毁所有缓存的单例bean。
*注意:不在父上下文上调用{@code close};
*父上下文有自己独立的生命周期。
*此方法可多次调用,无副作用:后续
*{@code close}对已关闭上下文的调用将被忽略。
*/
@凌驾
无效关闭();

stop()
不停用活动组件,但只停止当前正在进行的任务,并且在
start()之前不允许启动新组件
应用程序上下文或该活动组件的背面。

这可能会有所帮助:@Mahmoud Ben Hassine您能解释一下我如何在我的Launcher类中添加Lifecycle stop,因为我没有ApplicationContext。更新上面的我的代码。
app.run(args)
返回一个
ConfigurableApplicationContext
,您可以在适当的时候调用
stop
。我尝试了,但它仍然没有退出。您需要使用
context.close()
。这样所有的资源和线程都将被正确地清理
2018-09-03 11:03:45 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:03:45 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 11:03:45 INFO  [Thread-118] o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@c6f9085f: startup date [Mon Sep 03 11:02:56 BST 2018]; root of context hierarchy
2018-09-03 11:03:45 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans on shutdown
2018-09-03 11:03:45 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans
2018-09-03 11:03:45 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:03:46 INFO  [Thread-118] o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Started ResetRegressionDataBatchJob in 50.735 seconds (JVM running for 51.906)
2018-09-03 11:06:55 INFO  [main] c.p.c.i.batch.BaseRunnableBatchJob - **************** jobShouldBeRun: True (Default - No Override)
2018-09-03 11:06:55 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] launched with the following parameters: [{}]
2018-09-03 11:06:55 INFO  [main] o.s.batch.core.job.SimpleStepHandler - Executing step: [step1]
2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Running the Delete and Update Script for the Regression Reset Batch Job....
2018-09-03 11:06:55 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executing SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql]
2018-09-03 11:06:55 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executed SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql] in 193 ms.
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 11:06:55:282
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 11:06:55:528
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.246
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 11:06:55 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 11:49:50:052
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 11:49:50:342
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.290
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 11:49:50 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:49:50 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@fb5a33e4: startup date [Mon Sep 03 11:48:56 BST 2018]; root of context hierarchy
2018-09-03 11:49:50 INFO  [Thread-118] c.p.c.f.batch.ContextClosedHandler - Inside onApplicationEvent Shutting down ThreadPoolTaskExecutor
2018-09-03 11:49:50 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 0
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.endpoint.EventDrivenConsumer - Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.c.PublishSubscribeChannel - Channel 'application.errorChannel' has 0 subscriber(s).
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.endpoint.EventDrivenConsumer - stopped _org.springframework.integration.errorLogger
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase -2147483648
2018-09-03 11:49:50 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans on shutdown
2018-09-03 11:49:50 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans
2018-09-03 11:49:50 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:49:51 INFO  [Thread-118] o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2018-09-03 11:49:51 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskScheduler - Shutting down ExecutorService 'taskScheduler'
2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Started ResetRegressionDataBatchJob in 49.884 seconds (JVM running for 50.91)
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase -2147483648
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 0
2018-09-03 14:49:39 INFO  [main] c.p.c.i.batch.BaseRunnableBatchJob - **************** jobShouldBeRun: True (Default - No Override)
2018-09-03 14:49:39 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] launched with the following parameters: [{}]
2018-09-03 14:49:39 INFO  [main] o.s.batch.core.job.SimpleStepHandler - Executing step: [step1]
2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Running the Delete and Update Script for the Regression Reset Batch Job....
2018-09-03 14:49:39 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executing SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql]
2018-09-03 14:49:39 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executed SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql] in 181 ms.
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 14:49:39:363
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 14:49:39:594
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.231
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 14:49:39 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 0
2018-09-03 14:49:39 INFO  [main] o.s.i.endpoint.EventDrivenConsumer - Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-09-03 14:49:39 INFO  [main] o.s.i.c.PublishSubscribeChannel - Channel 'application.errorChannel' has 0 subscriber(s).
2018-09-03 14:49:39 INFO  [main] o.s.i.endpoint.EventDrivenConsumer - stopped _org.springframework.integration.errorLogger
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase -2147483648
public static void main(String [] args)  throws Exception{
        logger.info("Starting Regression Data Reset Batch job......");
        SpringApplication app = new SpringApplication(ResetRegressionDataBatchJob.class);
        app.setWebEnvironment(false);
        app.setBannerMode(Banner.Mode.OFF);
        ExitStatus exitStatus = app.run(args).getBean("resetRegressionDataBatchJob", ResetRegressionDataBatchJob.class).run(args);
        logger.info("ResetRegressionDataBatchJob exiting with status of "+exitStatus);
        if (!ExitStatus.COMPLETED.equals(exitStatus) && !ExitStatus.NOOP.equals(exitStatus))
            System.exit(-1);

    }
/**
 * Close this application context, releasing all resources and locks that the
 * implementation might hold. This includes destroying all cached singleton beans.
 * <p>Note: Does <i>not</i> invoke {@code close} on a parent context;
 * parent contexts have their own, independent lifecycle.
 * <p>This method can be called multiple times without side effects: Subsequent
 * {@code close} calls on an already closed context will be ignored.
 */
@Override
void close();