It's not a secret anymore!
The moose likes Other Application Frameworks and the fly likes Where to use Spring? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Where to use Spring?" Watch "Where to use Spring?" New topic

Where to use Spring?

gopi nath

Joined: Oct 05, 2006
Posts: 15
I Know Spring is an application Framework.thats all i know about Spring.

Now i am working Struts+Stateless EJB+ Hibernate Project
If i want to Spring, where i can use in my project?.
If Spring can replace any technology, what that technology would be?.
If i am using in my Project what would be advantage over current architecture?

Thanks in advance
Nick Larson

Joined: Apr 21, 2004
Posts: 7

Spring can be used in all parts of your project. Should it be used? That is really up to you. I think that is the nice part about Spring, you don't have to use it for every layer. I think the most difficult part to learn is the DI aspect of Spring. It is really a simple concept, but can take a while to make sense. Once you "get" it though, you sometimes wonder how you ever worked without it. By being able to inject your beans into your classes, you can code very quickly and switch out implementations quickly.

You can replace Struts with Spring MVC. Spring MVC is a bit different than Struts, but by no means any less effective or usable. I have done projects using both. I am really hooked on the Spring MVC right now, and would probably use it as my MVC framework of choice. (Still need to work with Struts 2 though...that could change my mind.) One of the main advantages I see with Spring MVC over Struts is that your web forms are bound directly to your backing object. So in your Controller (Action in Struts), you don't have to build your object from the form parameters. It will automatically do that, and do any validation that you have written up.

Your EJBs could also be replaced. By using Spring you can just make POJOs and use them. You can apply transactions and security through AOP, and you don't need to have an EJB container. So you could do everything in your web container.

The Hibernate side. We still use Hibernate, but the way Spring can help you here is by using the HibernateTemplate. It has all your connection logic built into it. You just grab your template, and execute your commands. You no longer need to worry about getting a connection, running your command and closing the connection. It is all done for you. And if you want to get away from Hibernate, there are also Templates for other ORMs or just JDBC calls.

Hope this helps...

gopi nath

Joined: Oct 05, 2006
Posts: 15
HI Nick
Thank For Your reply.

You can replace Struts with Spring MVC.
Your EJBs could also be replaced.
And if you want to get away from Hibernate, there are also Templates for other ORMs or just JDBC calls.

So Spring can replace Struts ,Ejbs, Hibernate.
So by Using only spring and Jsp we can make an Project Efficiently , am i right?
Is there is any disadvantage in using Spring?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

So Spring can replace Struts ,Ejbs, ...



No. But it can allow you to easily swap to another ORM.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nick Larson

Joined: Apr 21, 2004
Posts: 7
Like Paul said. Spring doesn't "replace" hibernate. Hibernate is a great tool, but Spring + Hibernate can make things a lot easier to do.

As far as disadvantages to Spring. I'm sure there are some somewhere. (Can't think of any right off the top of my head.) But Spring as a tool, isn't really a replacement for everything, but a way to make things easy and simple. Things like the JdbcTemplate, HibernateTemplate, JmsTemplate, DI (IoP), Quartz, Spring Security (Acegi), Spring Web Services...really do make things simpler. A lot of times these things are just wrappers on top of other technologies, but these wrappers make it possible to code with very little setup and boiler plate code. Again, back to the HibernateTemplate, this doens't replace Hibernate, as all the work is done by Hibernate, but by using Spring + Hibernate, you can write DAO's and functional code very quickly.

Try working with it for a bit. Do a couple of tutorials that can be found online. (Google Spring tutorial) Check out the example projects that are bundled with the Jars and Source. There are quite a few different ways to do things, and the Spring team does a good job of including example projects.

I agree. Here's the link:
subject: Where to use Spring?
jQuery in Action, 3rd edition