Java 如何在 Eclipse 中创建 Spring MVC 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2135289/
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-13 03:59:01  来源:igfitidea点击:

How do you create a Spring MVC project in Eclipse?

javaeclipsespringspring-mvceclipse-plugin

提问by Rob

I am trying to follow the basic tutorial for Spring MVC but got lost at creating a new project in Eclipse.
It seems to me that most tutorials assume you know how to create a Spring Project in Eclipse.
Any advice on where to get started or tutorials which explain how to set up Eclipse would be appreciated.

我正在尝试遵循 Spring MVC 的基本教程,但在 Eclipse 中创建一个新项目时迷失了方向。
在我看来,大多数教程都假设您知道如何在 Eclipse 中创建 Spring 项目。
任何关于从哪里开始的建议或解释如何设置 Eclipse 的教程将不胜感激。

采纳答案by danben

You want to create a "Dynamic Web Project". Follow the steps here: Spring MVC Tutorial with Eclipse and Tomcat.

您想创建一个“动态 Web 项目”。按照此处的步骤操作: Spring MVC Tutorial with Eclipse and Tomcat

Also, here is the Eclipse documentation for Dynamic Web Projects: http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/ccwebprj.html

此外,这里是动态 Web 项目的 Eclipse 文档:http: //help.eclipse.org/help32/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/ccwebprj.html

回答by Droo

You don't necessarily have to create a Spring project. Almost all Java web applications have he same project structure. In almost every project I create, I automatically add these source folder:

您不必创建Spring 项目。几乎所有 Java Web 应用程序都具有相同的项目结构。在我创建的几乎每个项目中,我都会自动添加这些源文件夹:

  • src/main/java
  • src/main/resources
  • src/test/java
  • src/test/resources
  • src/main/webapp*
  • 源代码/主/Java
  • 源代码/主要/资源
  • 源代码/测试/Java
  • 源代码/测试/资源
  • 源代码/主/网络应用程序*

src/main/webapp isn't actually a source folder. The web.xml file under src/main/webapp/WEB-INF will allow you to run your java application on any Java enabled web server (Tomcat, Jetty, etc.). I typically add the Jetty Pluginto my POM (assuming you use Maven), and launch the web app in development using mvn clean jetty:run.

src/main/webapp 实际上不是源文件夹。src/main/webapp/WEB-INF 下的 web.xml 文件将允许您在任何支持 Java 的 Web 服务器(Tomcat、Jetty 等)上运行您的 Java 应用程序。我通常将Jetty 插件添加到我的 POM(假设您使用 Maven),并使用mvn clean jetty:run在开发中启动 Web 应用程序。

回答by Sven Haiges

Download Spring STS (SpringSource Tool Suite) and choose Spring Template Project from the Dashboard. This is the easiest way to get a preconfigured spring mvc project, ready to go.

下载 Spring STS(SpringSource 工具套件)并从仪表板中选择 Spring 模板项目。这是获得预配置 spring mvc 项目的最简单方法,准备就绪。

回答by ishanbakshi

This is the easiest way :

这是最简单的方法:

step 1) install Spring Tool Suite (STS)for eclipse (version 3.7.0RELEASE or above) To do this you can go to Help >> eclipse market place , then type Spring Tool suite in search box.

步骤 1)为 Eclipse(版本 3.7.0RELEASE 或更高版本)安装 Spring Tool Suite (STS)为此,您可以转到 Help >> eclipse market place ,然后在搜索框中键入 Spring Tool Suite。

step 2) now go to file >> new >> spring projectas shown in the image below enter image description here

步骤 2) 现在转到文件 >> 新建 >> spring 项目,如下图所示 在此处输入图片说明

step 3)now choose the template as "spring MVC Project"and give a name to your project on the top as shown below ( I named it 'SpringProject') enter image description here

第 3 步)现在选择模板作为“spring MVC 项目”并在顶部为您的项目命名,如下所示(我将其命名为“SpringProject”) 在此处输入图片说明

step 4)now give a base package name like thisenter image description here

第 4 步)现在给出一个像这样的基本包名称在此处输入图片说明

and that is . The project will be created in a few minutes and Now you can right click on it and run on server.

那就是 。该项目将在几分钟内创建,现在您可以右键单击它并在服务器上运行。

回答by shailesh

  1. step 1: create a new "Dynamic Web Project" in eclipse.
  2. step 2: right click on the created project.
  3. step 3: click on "configure" option.
  4. step 4: click on "convert to maven project".
  1. 第 1 步:在 eclipse 中创建一个新的“动态 Web 项目”。
  2. 第 2 步:右键单击创建的项目。
  3. 第 3 步:点击“配置”选项。
  4. 第 4 步:单击“转换为 Maven 项目”。

here is more detailed information -> [1]: https://crunchify.com/simplest-spring-mvc-hello-world-example-tutorial-spring-model-view-controller-tips/

这里是更详细的信息-> [1]:https: //crunchify.com/simplest-spring-mvc-hello-world-example-tutorial-spring-model-view-controller-tips/