我正在使用 Spring Boot 构建一个命令行 java 应用程序以使其快速运行。
该应用程序加载不同类型的文件(例如 CSV)并将它们加载到 Cassandra 数据库中。它不使用任何 Web 组件,它不是 Web 应用程序。
我遇到的问题是在工作完成后停止应用程序。我正在使用带有 a 的 Spring CommandLineRunner 接口@Component
来运行任务,如下所示,但是当工作完成时,应用程序并没有停止,它出于某种原因继续运行,我找不到停止它的方法。
@Component
public class OneTimeRunner implements CommandLineRunner {
@Autowired
private CassandraOperations cassandra;
@Autowired
private ConfigurableApplicationContext context;
@Override
public void run(String... args) throws Exception {
// do some work here and then quit
context.close();
}
}
更新:问题似乎是spring-cassandra
,因为项目中没有其他内容。有谁知道为什么它让线程在后台运行以防止应用程序停止?
更新:通过更新到最新的 Spring Boot 版本,问题消失了。