运行 Spring 使用计划在 Azure WebJob 上启动应用程序

Running a Spring Boot App on Azure WebJob with a Schedule

我有一个常规 Java/Spring 批处理作业,每晚 运行 从一个数据库和 insert/update 我的项目数据库中获取数据。这在部署在 Tomcat.

上的当前设置中运行良好

现在我需要将其分离出来并 运行 在 Azure WebJob 上。什么是好的方法?

我可以使用 Spring Boot 来达到这个目的吗? 但我不确定它会如何运作。我的意思是,我可以为我的项目(使用 Spring Boot 编写的作业)创建一个 JAR 并将其复制到 Azure WebJob 上。然后有一个批处理文件 "java -jar..." 但是:

如果有人能帮我做这件事,我将不胜感激。

谢谢。

wouldn't it be like running and deploying the Spring Boot App with it's inbuilt web-server that will continue to run once I run it?

Spring 启动应用程序可以是非 Web 应用程序,一个很好的例子是 Spring 不依赖于 servlet 容器的启动批处理应用程序。

您可以创建一个 Spring 启动应用程序,该应用程序 运行 是您的 Spring 批处理作业,然后在作业完成时停止,而无需将其部署到(嵌入式) Tomcat。你可以在这里找到一个例子:https://spring.io/guides/gs/batch-processing/

secondly, the next time the batch file is executed by Azure WebJob as per the schedule I set it will try to run the Spring Boot App again and I will probably get bind exception since the port is already in use from the first run.

一旦你有了 运行 你的应用程序 java -jar mybatchapp.jar 的脚本,你就可以在需要时使用 Azure Scheduler 运行 你的工作。由于您的批处理应用程序没有 contain/start 嵌入式 servlet 容器,因此您不会遇到端口冲突。