Spring MVC 示例 Web 应用程序

发布于 2024-07-17 08:13:39 字数 250 浏览 7 评论 0原文

我正在寻找一个示例 Spring MVC 2.5 Web 应用程序,我可以轻松地:

  • 在 Eclipse 中设置为项目
  • 部署到本地应用程序服务器(使用 Ant/Maven)

Spring 发行版中包含几个示例应用程序(“petclinic”) ' 和 'jpetstore'),但它们不提供任何 Eclipse 项目文件(或生成它们的方法)。 对于我的需求来说,它们似乎也有点复杂,例如需要设置本地数据库。

I'm looking for an example Spring MVC 2.5 web app that I can easily:

  • Setup as a project in Eclipse
  • Deploy to a local app server (using 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

半仙 2024-07-24 08:13:39

启动和运行 Spring MVC 项目的最简单方法是使用 SpringSource 工具套件,这是另一个基于Eclipse的免费IDE。

IDE 和 Spring/Maven 之间的集成非常紧密,并且它附带了一个已设置的应用程序服务器,供您部署 Web 应用程序。

按照以下步骤获取可用的 Spring MVC Web 应用程序。

  1. 要在 STS 中设置新项目:单击文件 -> 新-> Spring 模板项目 -> Spring MVC 项目
  2. 要引入依赖项并编译您的项目:右键单击您的新项目 -> 运行方式-> Maven 安装
  3. 要在应用程序服务器内运行您的项目:右键单击您的新项目 -> 运行方式-> 在服务器上运行-> SpringSource tc Server

如果它有效,您将看到一个网页,显示“恭喜!您正在运行 Spring!”

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.

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.

Follow these steps to get a working Spring MVC web app.

  1. To setup a new project in STS: Click File -> New -> Spring Template Project -> Spring MVC Project
  2. To pull in dependencies and compile your project: Right click your new project -> Run As -> Maven install
  3. To run your project inside an application server: Right click your new project -> Run As -> Run on Server -> SpringSource tc Server

If it works, you'll see a web page saying "Congratulations! You're running Spring!"

乱了心跳 2024-07-24 08:13:39

虽然不是专门可以下载的应用程序,开发 Spring Framework MVC 应用程序步骤逐步涵盖使用 ant 构建脚本在 Eclipse 中创建 Spring 应用程序,并完成单元测试。

这满足以下要求:

  • Spring MVC 2.5
  • Eclipse 中的
  • 项目使用 Ant 部署到本地应用程序服务器 使用
  • HSQL(无需安装本地 DB)

While not specifically an app you can download, Developing a Spring Framework MVC application step-by-step covers creating a spring application in Eclipse with an ant build script, complete with unit tests.

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)
天冷不及心凉 2024-07-24 08:13:39

这里有一个 Spring MVC 的 Maven 原型(模板项目结构):

http://docs。 codehaus.org/display/MAVENUSER/Archetypes+List

这是此类调查的一个很好的起点。 要使用 Maven 创建原型,请首先安装 Maven:

http://maven.apache。 org/plugins/maven-install-plugin/

然后使用原型创建一个项目:

http://maven.apache.org/guides/introduction/introduction-to-archetypes.html

您还可以使用 Eclipse 的 m2eclipse 插件来简化此操作,它会带您完成使用向导的项目阶段。 只需右键单击-> 新项目-> 其他,Maven并选择原型。 希望有帮助。

There's a Maven archetype (template project structure) for Spring MVC here:

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:

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

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.

情绪失控 2024-07-24 08:13:39

生成 Eclipse 项目文件:
在将项目导入工作区之前使用 mvn eclipse:eclipse。 这将创建所有必需的配置文件,并将您的项目与所有必需的依赖项挂钩。

spring-samples 中的 mvc-basic 和 mvc-ajax 示例项目(SVN URL: https:// src.springframework.org/svn/spring-samples)是不需要任何本地数据库支持的简单项目。

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.

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.

半世晨晓 2024-07-24 08:13:39

使用AppFuse

Use AppFuse

另类 2024-07-24 08:13:39

我按照 Drew 的描述让它工作,但是对于新用户来说有一个陷阱(意味着全新安装,不熟悉 Maven 或 m2eclipse)。 你会得到这个错误:

[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /home/user/.m2/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>

我后来发现此错误报告。)
之后我就开始做生意了。 我什至能够导出为 WAR 文件并部署到我安装的 WebSphere Community Edition 上。 谢谢你,德鲁!


稍早一点,我写道:

哼。 没关系。 我放弃了,关闭了我的机器,当我回来时,一切正常(除了我正在处理的一个小 Maven 问题)。 把它归结为一个错误。


早些时候,我写道:

我很高兴听到 STS,所以我下载并安装了它。 一切都很顺利。 这是一台新机器,所以我拥有最新的一切 - java 1.6、eclipse 3.5.1 等。

在上述说明的步骤 2 中,我收到此错误:
“指定的 JRE 安装不存在”

我已经在所有能找到的地方设置了路径,所以我不确定它抱怨的是哪个 JRE。 帮助?

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:

[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 almost empty 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!


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.


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.

On step 2 of the above instructions, I get this error:
"The specified JRE installation does not exist"

I've set paths everywhere I can find, so I'm not sure which JRE it's complaining about. Help?

小ぇ时光︴ 2024-07-24 08:13:39

您也可以使用 Spring Roo 来执行此操作。 http://www.springsource.org/roo

You could also use Spring Roo to do this. http://www.springsource.org/roo

你的呼吸 2024-07-24 08:13:39

您可以使用下面的链接下载 hello world spring mvc 项目

Spring MVC hello world example

You can use below link to download hello world spring mvc project

Spring MVC hello world example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文