This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other Application Frameworks and the fly likes Spring in the business layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring in the business layer" Watch "Spring in the business layer" New topic
Author

Spring in the business layer

Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
I am confused. some articles say that Spring is similar to struts and is here to replace struts in web tier. and few say that Spring can be used in business tier with struts in web tier. Which is true? Can I use Spring in place of EJB's in business layer?

is this design possible?

Struts(Web tier) + Spring(Business layer) + Hibernate(Persistence layer)

Thanks in advance,

Angel
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
In short, yes.

Spring has several components that can be used with other Spring components, with other frameworks, or standalone. If you use Hibernate as your backend Spring can deal with transaction managment for you, and there are other benefits, but I'm not really an expert here. Once you have that you can use JSP, JSF, Sevlets, Struts, Spring, Tapestry, ect... for the frontend.

I believe you can also use Spring with JDO, EJB's, and some other persistence layers, as well as standalone, on the backend.

Spring was designed to be very flexible and modular.
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Yes sir, in addition to that you can use Spring as an AOP Framework. You can use it as your ORM or it can work with other ORM like Hibernate. You can also use it in building your web layer and for your view layer as an alternative to Struts or you can use it to work with Struts. You can also use it in managing your transaction that can work with different platform like JTA, Hibernate, JDBC and etc.
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
You can use it as your ORM or it can work with other ORM like Hibernate.

Not to be picky, but... Spring does not have its own ORM framework. It provides a framework that makes it much easier to work with JDBC, as well as integration with several ORM tools, such as Hibernate, JDO, iBATIS and OJB.

You can use it as your ORM or it can work with other ORM like Hibernate. You can also use it in building your web layer and for your view layer as an alternative to Struts or you can use it to work with Struts.

Just to be clear, Spring does not provide its own view technology. It does integrate with other view technologies like JSP, Tapestry and Velocity. It also provides Spring tags for easier integration.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Ryan Breidenbach:
Spring does not provide its own view technology.
I thought Spring MVC was a complete web framework. If not, is it merely missing the presentation layer (view in MVC) for which you can use any number of templating libraries?

Rod covered it only briefly in his book Professional Development Without Drinking the Kool-Aid -- er, I mean Without EJB -- but I was under the impression it was complete on its own.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
I think in this discussion definitions of view technology and MVC framework are mixed.
If I understand correctly, Struts doesn't offer a genuine view technology neither. You use a view technology like jsp, jsf, tapestry or velocity in a MVC framework to tell the browser how to render a view. And you know that. Its just a definitions overflow.
[ April 30, 2005: Message edited by: Axel Janssen ]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
You're right, of course. For the past several years I've been using Struts with an in-house XML + XSL -> HTML view layer. I'm pretty burnt out and it didn't even occur to me that Struts doesn't have its own view technology. Thanks for the correction.

So I guess Spring MVC is equivalent to Struts as far as the roles they play.
An Huiqiang
Greenhorn

Joined: May 01, 2005
Posts: 1
Originally posted by Angel Hafer:

Struts(Web tier) + Spring(Business layer) + Hibernate(Persistence layer)
Angel


My project is using this model.
But i think it is not the best.
Now i am studying jsf.
Maybe jsp+spring+hibernate is better.

Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
so, Struts + Spring + Hibernate is not good combination? I have been reading about them a lot.

This scares me.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Fear not. It's perfectly okay to use Spring with Struts and Hibernate.


James Carman, President<br />Carman Consulting, Inc.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by James Carman:
Fear not. It's perfectly okay to use Spring with Struts and Hibernate.


Sure, Struts/Spring/Hibernate is a fine way to develop an application. I think the reason some people dismiss this combination is that Struts 1.x (as we know it) is a dead/sick/dying project. There's nothing wrong with it, but there are better options available nowadays.

My favorite stack is Tapestry/Spring/Hibernate, but I also see some merit in JSF/Spring/Hibernate. I've also developed several apps using SpringMVC/Spring/Hibernate. To each his own.


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.
 
 
subject: Spring in the business layer