views:

565

answers:

6

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 .

A: 

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.

Here's the link

davek
A: 

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

iWerner
+2  A: 

4 Things you will need

  1. Spring Recipes by Gary Mak
  2. Sun's Java Tutorial for your Java brushing up
  3. Spring reference manual for 2.5.6 (Spring 3 is still in RC1)
  4. Spring 2.5.6 API docs

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 refcardz for Spring Configuration (also by Craig Walls) and Spring Annotations.

non sequitor
+2  A: 

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).

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!

Donal Boyle
A: 

I've found that the tutorials for the Appfuse framework are a great way to get aquainted with the basic features of 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.

The Spring documentation is 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 Roo is 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.

Jason Gritman
A: 

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

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:

<?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"&gt;

<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 :-)
yawn