Java spring MVC 示例 Web 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/777946/
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
spring MVC sample web app
提问by Dónal
I'm looking for an example Spring MVC 2.5 web app that I can easily:
我正在寻找一个示例 Spring MVC 2.5 web 应用程序,我可以轻松地:
- Setup as a project in Eclipse
- Deploy to a local app server (using Ant/Maven)
- 在 Eclipse 中设置为项目
- 部署到本地应用服务器(使用 Ant/Maven)
There are a couple of example applications included with the Spring distribution ('petclinic' and 'jpetstore'), but they don't provide any Eclipse project files (or a way to generate them). They also seem a bit complicated for my needs, e.g. require a local database to be setup.
Spring 发行版中包含几个示例应用程序(“petclinic”和“jpetstore”),但它们不提供任何 Eclipse 项目文件(或生成它们的方法)。对于我的需要,它们似乎也有点复杂,例如需要设置本地数据库。
采纳答案by Zack The Human
While not specifically an app you can download, Developing a Spring Framework MVC application step-by-stepcovers creating a spring application in Eclipse with an ant build script, complete with unit tests.
虽然不是您可以下载的特定应用程序,但开发 Spring Framework MVC 应用程序分步介绍了如何使用 ant 构建脚本在 Eclipse 中创建 Spring 应用程序,并完成单元测试。
This meets the following requirements:
这满足以下要求:
- Spring MVC 2.5
- Project in Eclipse
- Deploy to a local app server using Ant
- Uses HSQL (no need to install a local DB)
- 春季MVC 2.5
- Eclipse 中的项目
- 使用 Ant 部署到本地应用服务器
- 使用 HSQL(无需安装本地数据库)
回答by flybywire
Use AppFuse
使用 AppFuse
回答by Jon
There's a Maven archetype (template project structure) for Spring MVC here:
这里有一个 Spring MVC 的 Maven 原型(模板项目结构):
http://docs.codehaus.org/display/MAVENUSER/Archetypes+List
http://docs.codehaus.org/display/MAVENUSER/Archetypes+List
That's a good starting place for this kind of investigation. To create an archetype using Maven, first install Maven:
这是进行此类调查的良好起点。要使用 Maven 创建原型,首先安装 Maven:
http://maven.apache.org/plugins/maven-install-plugin/
http://maven.apache.org/plugins/maven-install-plugin/
and then create a project using the archetype:
然后使用原型创建一个项目:
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
You can also use the m2eclipse plugin for Eclipse to simplify this and it takes you through the stages of the project using a wizard. Just right click -> New Project -> Other, Maven and select the archetype. Hope that helps.
您还可以使用 Eclipse 的 m2eclipse 插件来简化这一过程,它会使用向导引导您完成项目的各个阶段。只需右键单击 -> 新建项目 -> 其他,Maven 并选择原型。希望有帮助。
回答by Drew
The easiest way to get up and running with a Spring MVC project is to use SpringSource Tool Suite, which is another free IDE based on Eclipse.
启动和运行 Spring MVC 项目的最简单方法是使用SpringSource Tool Suite,它是另一个基于 Eclipse 的免费 IDE。
The integration between the IDE and Spring/Maven is tight, and it comes with an application server already setup for you to deploy your web app.
IDE 和 Spring/Maven 之间的集成很紧密,它带有一个已经设置好的应用服务器,供您部署 Web 应用程序。
Follow these steps to get a working Spring MVC web app.
按照以下步骤获取可运行的 Spring MVC Web 应用程序。
- To setup a new project in STS: Click File -> New -> Spring Template Project -> Spring MVC Project
- To pull in dependencies and compile your project: Right click your new project -> Run As -> Maven install
- To run your project inside an application server: Right click your new project -> Run As -> Run on Server -> SpringSource tc Server
- 在 STS 中设置一个新项目:点击 File -> New -> Spring Template Project -> Spring MVC Project
- 要引入依赖项并编译您的项目:右键单击您的新项目 -> Run As -> Maven install
- 要在应用程序服务器中运行您的项目:右键单击您的新项目 -> Run As -> Run on Server -> SpringSource tc Server
If it works, you'll see a web page saying "Congratulations! You're running Spring!"
如果它有效,您将看到一个网页,上面写着“恭喜!您正在运行 Spring!”
回答by Travis Low
I got it working just as Drew described, but there is a trap for new users (meaning fresh install, no familiarity with Maven or m2eclipse). You'll get this error:
我按照 Drew 描述的那样工作,但是新用户有一个陷阱(意味着全新安装,不熟悉 Maven 或 m2eclipse)。你会得到这个错误:
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /home/user/.m2/settings.xml
And the work around is to just make an almostempty settings.xml:
解决方法是创建一个几乎为空的 settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
</settings>
(I later found this bug report.) After that, I was in business. I was even able to export as a WAR file and deploy onto my installation of WebSphere Community Edition. Thank you, Drew!
(我后来发现了这个错误报告。)在那之后,我开始做生意了。我什至能够导出为 WAR 文件并部署到我的 WebSphere Community Edition 安装中。谢谢你,德鲁!
A little less earlier, I wrote:
稍早一点,我写道:
Hmph. Never mind. I gave up, shut down my machine, and when I came back, everything worked (except for a minor Maven issue I'm working on). Chalk it up to a bug.
哼。没关系。我放弃了,关闭了我的机器,当我回来时,一切正常(除了我正在处理的一个小 Maven 问题)。把它归结为一个错误。
Earlier, I wrote:
早些时候,我写道:
I was very excited to hear about STS, so I downloaded and installed it. It went perfectly. This is a new machine, so I have the latest of everything - java 1.6, eclipse 3.5.1, etc.
听到 STS 我很兴奋,所以我下载并安装了它。它进行得很顺利。这是一台新机器,所以我拥有最新的一切——java 1.6、eclipse 3.5.1 等。
On step 2 of the above instructions, I get this error: "The specified JRE installation does not exist"
在上述说明的第 2 步中,出现此错误:“指定的 JRE 安装不存在”
I've set paths everywhere I can find, so I'm not sure which JRE it's complaining about. Help?
我在我能找到的所有地方都设置了路径,所以我不确定它在抱怨哪个 JRE。帮助?
回答by JAWspeak
You could also use Spring Roo to do this. http://www.springsource.org/roo
您也可以使用 Spring Roo 来执行此操作。http://www.springsource.org/roo
回答by Jatin
To generate Eclipse project files: Use mvn eclipse:eclipse before importing the project into your workspace. This will create all required configuration files and hook your project up with all the required dependencies.
要生成 Eclipse 项目文件: 在将项目导入工作区之前使用 mvn eclipse:eclipse。这将创建所有必需的配置文件,并将您的项目与所有必需的依赖项挂钩。
The mvc-basic and mvc-ajax sample projects in spring-samples (SVN URL: https://src.springframework.org/svn/spring-samples) are simple projects that do not need any local database support.
spring-samples 中的 mvc-basic 和 mvc-ajax 示例项目(SVN URL:https: //src.springframework.org/svn/spring-samples)是不需要任何本地数据库支持的简单项目。
回答by resmo
Just spotted http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/which could be interessting for you.
刚刚发现http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/这对你来说可能很有趣。
回答by chirag20388
You can use below link to download hello world spring mvc project
您可以使用以下链接下载 hello world spring mvc 项目