点击蓝字
![640?wx_fmt=gif](https://img-blog.csdnimg.cn/img_convert/5bfd7220471113f935fa7a6d44dd0720.gif)
关注我们
在本文中,我们将讨论运行SpringBoot应用程序的不同方法:
1.从IDE运行
2.作为打包应用程序运行
3.使用Maven插件
4.使用外部Tomcat
5.使用Gradle插件
![640?wx_fmt=jpeg](https://img-blog.csdnimg.cn/img_convert/13e7a0d901d98846611ee3b14ddebdfd.png)
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/2e368488de02aa318ab2b8bc3746dc0c.png)
从IDE运行
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f512f9fadd63cd6bbcba3612bcc4ab16.png)
你可以在IDE中作为简单的Java应用程序(Application.java或main类)运行SpringBoot应用程序。
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/416ffd32e044ad387333ed72d17ee1d8.png)
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/2e368488de02aa318ab2b8bc3746dc0c.png)
作为打包应用程序运行
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f512f9fadd63cd6bbcba3612bcc4ab16.png)
如果使用SpringBootMaven或Gradle插件创建可执行JAR,则可以使用爪哇-JAR。例如,需要将目录更改为当前项目目录,并在cmd中运行以下命令。
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/019b38dec20cc33b98571867a3a65c2b.png)
还可以在启用远程调试支持的情况下运行打包应用程序。这样做可以将调试器附加到打包的应用程序,如下面的示例所示:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/414f1be1921be8f396a04679c583ba53.png)
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/2e368488de02aa318ab2b8bc3746dc0c.png)
使用Maven插件
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f512f9fadd63cd6bbcba3612bcc4ab16.png)
SpringBootMaven插件包括一个跑可用于快速编译和运行应用程序的目标。应用程序以爆炸性的形式运行,就像它们在您的IDE中所做的那样。下面的示例显示了运行SpringBoot应用程序的典型Maven命令:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/e6dfb2b8ae7f66dc429896134c8d08b9.png)
我们也可以使用Maven选择操作系统环境变量,如以下示例所示:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/8430821b07264723e56e0c32274ac9ed.png)
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/2e368488de02aa318ab2b8bc3746dc0c.png)
使用外部Tomcat
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f512f9fadd63cd6bbcba3612bcc4ab16.png)
我们还可以将SpringBootWeb应用程序WAR文件部署到外部Tomcatservlet容器中。我们可以按照三个步骤创建WAR文件并在外部Tomcatservlet容器中部署。
1
更改打包类型
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/709d47a8143f788ecacc331c35283aaf.png)
2
添加SpringBoot-Start-Tomcat作为提供的范围
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/6f49c8f8b12e37a7099d6aeef593b01f.png)
3
主类扩展SpringBootServlet均衡器
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/b3933817dabb9e1a0e4f6818b32cbed9.png)
你可以了解有关如何将SpringBootWAR文件部署到外部Tomcat服务器的更多信息。
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/2e368488de02aa318ab2b8bc3746dc0c.png)
使用Gradle插件
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f512f9fadd63cd6bbcba3612bcc4ab16.png)
SpringBootGradle插件还包括bootRun 可用于以爆炸性形式运行应用程序的任务。bootRun 当你应用
org.springframework.boot 和Java插件,如下面的示例所示:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/72a59352683f94f2701f045bdae5ae4f.png)
你可能还需要使用爪哇选项操作系统环境变量,如以下示例所示:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/6503a5f0f6e1fda05aabc3c7fa84d812.png)
看到这里,你想不想踩在过来人的肩膀上,轻松实现专业技能的提升呢?不妨扫码加入java技术交流分享群,体验精彩公开课,还能免费领取更多学习资料。
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/c79e93be344acbf35a826f400c0afe42.png)
加入「java技术交流分享群」,开启你的技能提升之旅吧~
![640?wx_fmt=jpeg](https://img-blog.csdnimg.cn/img_convert/33237edfb90c8c4bbcb58af4a4a04606.png)
Java高级部落
共享Java行业资讯,分享公司内部核心干货,中高Java开发级技术,关注我一起探索Java编程架构之路。
![640?wx_fmt=gif](https://img-blog.csdnimg.cn/img_convert/936e0ae7f76481d75bcdadfbeeb6c587.gif)
更多精彩内容,尽在阅读原文