*
The moose likes Spring and the fly likes Why Spring? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Why Spring?" Watch "Why Spring?" New topic
Author

Why Spring?

Aaron Diffenderfer
Greenhorn

Joined: Mar 24, 2009
Posts: 12
I know of several groups in our company that are considering implementing Spring. What do you think are the biggest advantages & disadvantages? In other words, why use Spring?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Aaron Diffenderfer wrote:I know of several groups in our company that are considering implementing Spring. What do you think are the biggest advantages & disadvantages? In other words, why use Spring?


Pre EJB 3.0 world the answer to this question would be "Simplicity" in building a full stack J2EE app.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Aaron Diffenderfer wrote:, why use Spring?

In case you want to use dependency injection in your application and make your component less knowledgeable about the others implementation.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Gail Anderson
Author
Ranch Hand

Joined: Jul 07, 2009
Posts: 44
In the big picture of software design, Spring helps the software architect build loosely coupled systems.

It does this by having you code to Java interfaces. When you implement the interface with an appropriate Java class, you "configure" the implementation class using either annotations or xml. This is called bean wiring. Behind the scenes, the Spring container makes sure the correct class is plugged in. This is called dependency injection, where the system dependencies are "injected" by the Spring container. The dependencies, therefore, are not hardwired, but specified externally.

The beauty is that you can plug and play implementation classes (for example, you can implement persistence using Spring JDBC, "native JDBC", Spring JPA, native JPA). With JPA (Java Persistence API) you can use EclipseLink, Hibernate, etc.. It also makes it easy to implement different front-end frameworks. I have implemented the same system using both Swing and JSF 2. When you deal with well-designed service modules, this type of reimplementation is straightforward.

The disadvantage is that XML configuration can be verbose. Annotations are generally easier to read, but may be spread out in different source files.

In my opinion, building loosely coupled systems far outweighs any disadvantages.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Everything that has been said about Spring keeping coupling low is true and is a good message to send.

But so what? Does that mean that it's impossible to write loosely coupled code without Spring? Of course not. Dependency injection can be done by hand or you could choose other DI frameworks and accomplish the same loose-coupling.

What makes Spring special is that it's not *just* the dependency injection and AOP. Beyond that there's declarative security, caching, and transactions. There's cool support for working with scheduled jobs and asynchronous methods. You'll find abstractions for remoting and for JMS. And there's a web framework. And a webflow framework. Keep going and you'll find projects to help with integration (ala the Integrations Patterns book) and batch processing. Step out a bit more and you see abstractions for working with various types of datastores (including NoSQL databases). Keep looking and you'll find support for building mobile web applications, Android apps, and applications that interact with social networks. And then....there's more...but you should get the picture...

Spring has something for most any need...and if something's not there, it's open-source and we'd be pleased to see you contribute it.


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Keep looking and you'll find support for building mobile web applications, Android apps, and applications that interact with social networks. And then....there's more...but you should get the picture...


Did you mean there is some support for connecting to FB/FS/Twitter using Spring?
Do you have any chapter in your book dedicated for these?


Thanks and Regards,
~Sujoy
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Sujoy Choudhury wrote:Did you mean there is some support for connecting to FB/FS/Twitter using Spring?
Do you have any chapter in your book dedicated for these?


It's not in the book, but yes...Spring Social (http://www.springframework.org/spring-social) enables apps to connect to services such as Facebook and Twitter without having to muck about with the finer details of OAuth or individual provider REST APIs. In fact, I pushed out the 1.0.0.RC2 release of Spring Social tonight! Check it out and let me know what you think.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Thanks a lot Craig!!!
Raja Pal
Ranch Hand

Joined: Jul 12, 2004
Posts: 92
Craig sold pretty much, so much of Spring that took me 2 years to figure out, but now I am bowled over by Spring Social. Guys at springsource are doing a good job and we did rather contribute our bit. Infact this is one framework that half the IT projects swear by! I'd like to add the beauty of its Webservices integration which works with nearly all known protocols. Another beauty is it is compartmentalized, you can configure which parts of spring your app needs and send only those to deployment without the overhead of having a 200MB load of jar files that comes with a standards compliant app server!


Java Pal - Your friend in technology and innovation...India.
Rohit Mehta
Ranch Hand

Joined: Mar 11, 2005
Posts: 79

Though its very well clarified by Craig & others .. would like to add my bit ..
Nice AJAX libraries support, same for web services, almost all good coding practices & design patterns in use, easy to test components, nice use of aspects ....
no need to look beyond !
Rahul Mishra
Ranch Hand

Joined: Jan 22, 2006
Posts: 211
One of the aspects of spring..which i am crazy about..besides the usual..is the effort spring developers take to write code...

There have been a few instances when i have had to extend spring projects (extended spring web services during its infancy)..and the code documentation made it a breeze to extend and develop custom features...


OCMJEA/SCEA, SCDJWS, SCBCD 1.3, SCJP 1.4
My SCEA experience:http://javalogue.blogspot.com/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why Spring?
 
Similar Threads
Connecting Spring and Hibernate
Frameworks
Spring Annotation
WA #1.....word association
why spring and not grails or griffon?