Java 如何在 Eclipse 本身中运行 Spring Boot Web 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23677808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:38:41  来源:igfitidea点击:

How to run Spring Boot web application in Eclipse itself?

javaspringeclipsespring-boot

提问by Krishan Babbar

I am able to run few sample applications in my Eclipse (STS). Now, I want to run a web application within eclipse itself.

我能够在我的 Eclipse (STS) 中运行几个示例应用程序。现在,我想在 eclipse 本身中运行一个 Web 应用程序。

I tried with sample application "spring-boot-sample-web-jsp" given at the linkand I am able to export its war into external tomcat and run the application. Now my question is how to run a Spring Boot Web application into eclipse itself?

我试图在给定的样本应用程序“春天引导样本的web-JSP”链接,我能够将其War导出到外部Tomcat和运行应用程序。现在我的问题是如何将 Spring Boot Web 应用程序运行到 eclipse 本身中?

回答by geoand

Just run the mainmethod which is in the class SampleWebJspApplication. Spring Boot will take care of all the rest (starting the embedded tomcat which will host your sample application).

只需运行类中的main方法SampleWebJspApplication。Spring Boot 将负责所有其余的工作(启动将托管您的示例应用程序的嵌入式 tomcat)。

回答by Darren Parker

This answer is late, but I was having the same issue. I found something that works.
In eclipse Project Explorer, right click the project name -> select "Run As" -> "Maven Build..."
In the goals, enter spring-boot:runthen click Run button.

这个答案很晚,但我遇到了同样的问题。我发现了一些有效的东西。
在 eclipse Project Explorer 中,右键单击项目名称 -> 选择“Run As” -> “Maven Build...”
在目标中,输入spring-boot:run然后单击 Run 按钮。

I have the STS plug-in (i.e. SpringSource Tool Suite), so on some projects I will get a "Spring Boot App" option under Run As. But, it doesn't always show up for some reason. I use the above workaround for those.
Here is a reference that explains how to run Spring boot apps:
Spring boot tutorial

我有STS插件(即SpringSource Tool Suite),所以在一些项目中我会在Run As下得到一个“Spring Boot App”选项。但是,由于某种原因,它并不总是出现。我使用上述解决方法。
这是解释如何运行 Spring boot 应用程序的参考:
Spring boot 教程

回答by Paulo Merson

You can also use the "Spring Boot App" run configuration. For that you'll need to install the Spring Tool Suite plug-in for Eclipse.

您还可以使用“Spring Boot App”运行配置。为此,您需要为 Eclipse安装Spring Tool Suite 插件

回答by Md. Kamruzzaman

Steps: 1. go to Run->Run configuration -> Maven Build -> New configuration
2. set base directory of you project ie.${workspace_loc:/shc-be-war}
3. set goal spring-boot:run
4. Run project from Run->New_Configuration

步骤: 1. 转到 Run->Run configuration -> Maven Build -> New configuration
2. 设置项目的基本目录 ie.${workspace_loc:/shc-be-war}
3. 设置目标 spring-boot:run
4 . 从 Run->New_Configuration 运行项目

enter image description here

在此处输入图片说明

回答by deepak prajapati

First Method:(if STS is available in eclipse)
1.right click on project->run as ->Spring Boot app.

第一种方法:(如果STS在eclipse中可用)
1.右键单击项目->运行方式->Spring Boot应用程序。

Second Method:
1.right click on project->run as ->run configuration
2. set base directory of you project ie.${workspace_loc:/first}
3. set goal spring-boot:run
4. Run

第二种方法:
1.右键单击项目->运行方式->运行配置
2.设置项目的基本目录即${workspace_loc:/first}
3.设置目标 spring-boot:run
4.运行

Third Method:
1.Right click on @SpringBootApplication annotation class ->Run as ->Java Application

第三种方法:
1.右键@SpringBootApplication注解类->Run as->Java Application

回答by JefinOJ

In my case, I had to select the "src/main/java" and select the "Run As" menu Just like this, so that "Spring Boot App" would be displayed as here.

在我的情况下,我必须选择“src/main/java”并选择“Run As”菜单 就像这样,这样“Spring Boot App”就会显示为here

回答by Rajyawardhan Singh Panwar

I was also trying to run Spring Boot application in Eclipse, without any plugins.

我还尝试在 Eclipse 中运行 Spring Boot 应用程序,没有任何插件。

Step 1

第1步

Right click on your project. Select "Run As" -> "Maven build...". Then in "Goals" field, enter "spring-boot:run". Apply & Run.

右键单击您的项目。选择“运行方式”->“Maven 构建...”。然后在“目标”字段中,输入“spring-boot:run”。应用和运行。

After this you do not have to Run again.

在此之后,您不必再次运行。

Step 2

第2步

After making any change, clean your project. After cleaning, it automatically builds the project once. Then when you will refresh your pages on browser, change will be reflected.

进行任何更改后,请清理您的项目。清理后,它会自动构建项目一次。然后当您在浏览器上刷新页面时,更改将被反映。

回答by Prabhakar Kumar Ojha

If you are doing code in STS you just need to add the devtools dependency in your maven file. After that it will run itself whenever you will do some change.

如果你在 STS 中做代码,你只需要在你的 maven 文件中添加 devtools 依赖项。之后,只要您进行一些更改,它就会自行运行。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>