java 协助需要使 Spring MVC 项目与 IntelliJ IDEA 一起运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3119280/
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
Assistance need to get Spring MVC project going with IntelliJ IDEA
提问by Blankman
So I downloaded a trial of idea ultimate, and I want to get spring mvc going with tomcat.
所以我下载了idea Ultimate的试用版,我想让spring mvc和tomcat一起运行。
So I setup a new project, configured it to use sun jdk.
所以我设置了一个新项目,将其配置为使用 sun jdk。
I chose a spring application, and it created and downloaded the following:
我选择了一个 spring 应用程序,它创建并下载了以下内容:
I don't see any spring-mvc libraries, are they included in there or do I have to do something about that?
我没有看到任何 spring-mvc 库,它们是否包含在其中,或者我必须对此做些什么?
Can someone outline what I have to do to get this to build like a spring mvc web application?
有人可以概述我必须做什么才能像 spring mvc Web 应用程序一样构建它吗?
回答by Pavel
I find that the best way to start a new IDEA project is to use the Maven. This allows you to easily build your project without launching the IDE, automatically maintaining all libraries for you.
我发现启动新 IDEA 项目的最佳方式是使用 Maven。这使您无需启动 IDE 即可轻松构建项目,自动为您维护所有库。
"Create project from scratch", then select "Maven module" in the next screen. Click on "Create from archetype" and select the "maven-archetype-webapp". This will give you a basic Maven layout which builds a simple WAR file.
“从头开始创建项目”,然后在下一个屏幕中选择“Maven 模块”。单击“从原型创建”并选择“maven-archetype-webapp”。这将为您提供一个基本的 Maven 布局,它构建一个简单的 WAR 文件。
Now to add the Spring libraries, open the Maven build file - pom.xml - and insert a new dependency on the Spring MVC framework:
现在要添加 Spring 库,打开 Maven 构建文件 - pom.xml - 并在 Spring MVC 框架上插入一个新的依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
From here, you can follow the Spring MVC reference documentation- add the Dispatcher Servlet and Context Listener to web.xml, a Spring XML context and so on.
从这里开始,您可以按照Spring MVC 参考文档- 将 Dispatcher Servlet 和 Context Listener 添加到 web.xml、一个 Spring XML 上下文等。
Something else you might find useful is the Maven Jetty plugin. Once configured, you can run your app by simply typing "mvn jetty:run" at the command prompt (or launching it from within the IDE). Maven will fetch all that's required and deploy the app for you, no need for an external app server setup for quick testing.
您可能会发现有用的其他东西是Maven Jetty 插件。配置完成后,您只需在命令提示符下键入“mvn jetty:run”即可运行您的应用程序(或从 IDE 中启动它)。Maven 将获取所需的所有内容并为您部署应用程序,无需为快速测试设置外部应用程序服务器。
回答by Jake
I'm not sure if your setup would be identical to mine, but when I downloaded spring-framework-2.5.6 there were jar files named spring-web.jar, spring-webmvc.jar, etc. in the \dist\modules subfolders. The tutorial indicated at least spring-webmvc.jar should be in your WEB-INF/lib folder.
我不确定您的设置是否与我的相同,但是当我下载 spring-framework-2.5.6 时,\dist\modules 中有名为 spring-web.jar、spring-webmvc.jar 等的 jar 文件子文件夹。该教程指出至少 spring-webmvc.jar 应该在您的 WEB-INF/lib 文件夹中。
This tutorial optionally used eclipse, but might be helpful anyways, especially getting started:
本教程可选择使用 eclipse,但无论如何可能会有所帮助,尤其是入门:
http://static.springsource.org/docs/Spring-MVC-step-by-step/
http://static.springsource.org/docs/Spring-MVC-step-by-step/
回答by Ian Dallas
I think there are specific JARs for the Spring MVC stuff. Basically when you download the latest Spring Frameworkand you extract the zip you need to go to the dist folder and add the org.springframework.web.jar and org.springframework.web.servlet.jar/org.springframework.portlet.jar to your project. I'm pretty sure that the servlet/portlet jars will have your MVC specific classes.
我认为 Spring MVC 的东西有特定的 JAR。基本上,当您下载最新的Spring Framework并解压缩 zip 时,您需要转到 dist 文件夹并将 org.springframework.web.jar 和 org.springframework.web.servlet.jar/org.springframework.portlet.jar 添加到你的项目。我很确定 servlet/portlet jar 将具有您的 MVC 特定类。


