eclipse 开始使用 spring 框架

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

getting started with spring framework

eclipsespringspring-mvc

提问by Dónal Boyle

What is the best way to start with spring framework, I've already got a book Spring in action 2nd edition august 2007, but here is the thing, I'm missing some general knowledge concerning this framework and java. I've started reading the book but its not very clear to me, its clear what the author is trying to accomplish but I can't seem to re-write his examples. I'm using eclipse for code writing and I'm somewhat confused where to put xml file and where java files .. etc .

什么是开始使用 spring 框架的最佳方式,我已经在 2007 年 8 月出版了一本书 Spring in action 2nd edition,但问题是,我缺少一些关于这个框架和 java 的一般知识。我已经开始阅读这本书,但对我来说不是很清楚,作者想要完成的事情很清楚,但我似乎无法重写他的例子。我正在使用 eclipse 进行代码编写,但我有点困惑将 xml 文件放在哪里以及将 java 文件放在哪里……等等。

回答by non sequitor

4 Things you will need

你需要的4件事

  1. Spring Recipesby Gary Mak
  2. Sun's Java Tutorialfor your Java brushing up
  3. Spring reference manualfor 2.5.6 (Spring 3 is still in RC1)
  4. Spring 2.5.6 APIdocs
  1. Gary Mak春季食谱
  2. Sun 的 Java 教程,让您重温 Java
  3. 2.5.6 的Spring 参考手册(Spring 3 仍在 RC1 中)
  4. Spring 2.5.6 API文档

You have to buy Spring Recipes but it is a def MUST have, it will help you a lot and the others are free and indispensable. BTW Craig Walls book is quite good as well. You should also download the refcardzfor Spring Configuration (also by Craig Walls) and Spring Annotations.

您必须购买 Spring Recipes,但它是绝对必须的,它将对您有很大帮助,而其他的则是免费且不可或缺的。顺便说一句,Craig Walls 的书也很不错。您还应该下载Spring Configuration(也是 Craig Walls 提供)和 Spring Annotations的refcardz

回答by Dónal Boyle

To quickly see a project and some code in action you should check out the SpringSource Tools Suite(It's free and based on eclipse).

要快速查看项目和一些代码,您应该查看SpringSource 工具套件(它是免费的,基于 eclipse)。

The "STS Dashboard" contains tutorials for a bunch of Spring topics and the nice thing is they setup an actual project and walk you through the code. For web based applications it will even deploy to tomcat so you can see it working. At the end, you have a working project to play around with!

“STS 仪表板”包含一系列 Spring 主题的教程,好处是它们设置了一个实际项目并引导您完成代码。对于基于 Web 的应用程序,它甚至会部署到 tomcat,以便您可以看到它的工作情况。最后,您有一个可以玩的工作项目!

回答by yawn

Try experimenting with the minimal basics using the dependency injection container only. Initialize a simple application context like this, where applicationContext.xmlis at the top of your classpath.

尝试仅使用依赖注入容器来尝试最少的基础知识。像这样初始化一个简单的应用程序上下文, whereapplicationContext.xml位于类路径的顶部。

AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
context.registerShutdownHook();

Use a simple (copy and pasted right from my IDE, most of the imported schemas are not important for you) application context definition like this:

使用一个简单的(直接从我的 IDE 复制和粘贴,大多数导入的模式对您来说并不重要)应用程序上下文定义,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:lang="http://www.springframework.org/schema/lang"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="HelloWorld" class="java.lang.String" lazy-init="false">
    <constructor-arg value="Hello world"/>
</bean>

  • Read the high level reference(focusing on chapter 3 and 4) and after that Spring by example.
  • After reading chapter 3 you should be able to define simple beans with dependencies and FactoryBeans.
  • Learn about <context:component-scan .../>to be able to omit some bean declarations.
  • Come back to SO to ask more questions :-)
  • 阅读高级参考(重点是第 3 章和第 4 章),然后阅读Spring by example
  • 阅读第 3 章后,您应该能够定义具有依赖项和 FactoryBeans 的简单 bean。
  • 了解如何<context:component-scan .../>能够省略一些 bean 声明。
  • 回来问更多问题:-)

回答by Wernsey

There was a series of Spring articles/tutorials in InformIT's Java Reference Guidea while back which you may find useful.

InformIT 的Java 参考指南中有一系列 Spring 文章/教程,您可能会发现它们很有用。

回答by Jason Gritman

I've found that the tutorials for the Appfuse frameworkare a great way to get aquainted with the basic features of Spring.

我发现Appfuse 框架的教程是熟悉 Spring 基本特性的好方法。

Although they are a few years old, I'd also recommend any of the books by Rod Johnson where he lays out the the Spring design and philosophy: Expert One-on-One J2EE Design and Development, Expert One-on-One J2EE Development without EJB, and Professional Java Development with the Spring Framework.

虽然它们已经有几年的历史了,但我也推荐 Rod Johnson 撰写的任何一本阐述 Spring 设计和哲学的书: Expert One-on-One J2EE Design and Development, Expert One-on-One J2EE Development不使用 EJB使用 Spring 框架进行专业 Java 开发

The Spring documentationis great and I still usually learn something new every time I visit there. The first few chapters will help you understand some of the core concepts of Spring (i.e. Inversion of Control/Dependency Injection).

Spring文档是伟大的,我还是平时每天新我访问有时间学习的东西。前几章会帮助你理解Spring的一些核心概念(即控制反转/依赖注入)。

Spring Roois a new project that can help you build the infrastructure for a Spring-based application quickly, but I haven't seen any tutorials for it yet that would help you understand it yet.

Spring Roo是一个新项目,可以帮助您快速构建基于 Spring 的应用程序的基础设施,但我还没有看到任何可以帮助您理解它的教程。

回答by davek

I used the book "Spring Persistence a running Start" and some tutorials I found on the web for eclipse/java/maven etc. and was up and running(-ish) within a couple of weeks. I also had other spring books at my disposal, but found the "running start" one by far the best as it covered JPA and hibernate as well.

我使用了“Spring Persistence a running Start”一书和我在网上找到的一些关于 eclipse/java/maven 等的教程,并在几周内启动并运行(-ish)。我还有其他春季书可供我使用,但我发现“运行开始”是迄今为止最好的一本,因为它也涵盖了 JPA 和休眠。

Here's the link

这是链接