aspose file tools*
The moose likes Other Application Frameworks and the fly likes To authors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "To authors" Watch "To authors" New topic
Author

To authors

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Hi,
Does the book cover the merits of spring over EJB ?


Groovy
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
I think the best source to critizice ejb are the ones by Rod Johnson himself. I am owning Spring in Action and I see the strength of it more in the hands on introduction of the many aspects comprised in the spring framework than a high level architectonical discussion.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Pradeep Bhat:
Does the book cover the merits of spring over EJB ?


Only to some degree. As someone else posted to this thread, Rod Johnson's original J2EE Design & Development does more justice to this topic.

With that said, let me summarize my feelings about Spring vs. EJB:

POJOs are simpler, easier to manage, and easier to test than EJBs. (Note that I'm not saying EJBs are untestable...just that you have to jump through a few more hoops.)

Spring lets you develop an entire application, front-to-back, using POJOs. To be more accurate and pertinent to this discussion, Spring lets you develop your service layer using POJOs--Hibernate and other ORMs let you develop your peristence layer using POJOs.

The main things that EJB brought to the table were declarative transactions, declarative security, and remoting...but you had to do this all within EJB's non-POJO framework. Spring brings declarative transactions to POJOs, using AOP. Acegi (a security framework based on Spring) brings declarative security to POJOs, again using Spring AOP. With regard to remoting, EJBs were accessed locally more often than not, so that may not have been a big deal. But if it is to your project, then Spring also offers several options for remoting, including RMI, Hessian/Burlap, web services, and Spring's own HttpInvoker.

So if Spring lets you do a lot of EJB-like things using POJOs, then what good are EJBs? Well, they certainly lose a lot of their luster when Spring is around. But EJBs still have their place. Perhaps you have a legacy system that exposes services via EJBs. Or perhaps (for political or other non-technical reasons) your project is forced into EJBs. And EJBs also excel at distributed transactions. The good news is that you can still use Spring with EJBs...in two ways:

First, you can develop your EJBs such that they are Spring-aware and thus you can wire Spring beans into your EJBs. This lets you write a session bean that is merely a facade to Spring-managed service beans that do the real work.

Second (and probably the coolest thing) is that you can wire an EJB into your POJOs
without the POJOs being aware that their dealing with an EJB!!! As far as your POJOs are concerned, their talking to another POJO (when, in reality there's an EJB out there). Spring handles everything, include the nasty RemoteExceptions.


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.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

The main things that EJB brought to the table were declarative transactions, declarative security, and remoting...but you had to do this all within EJB's non-POJO framework. Spring brings declarative transactions to POJOs, using AOP. Acegi (a security framework based on Spring) brings declarative security to POJOs, again using Spring AOP. With regard to remoting, EJBs were accessed locally more often than not, so that may not have been a big deal. But if it is to your project, then Spring also offers several options for remoting, including RMI, Hessian/Burlap, web services, and Spring's own HttpInvoker.

Thanks a lot.

Does the Spring framework do any kind of object pooling like the EJB container? Thanks
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
Originally posted by Pradeep Bhat:

Thanks a lot.

Does the Spring framework do any kind of object pooling like the EJB container? Thanks


Yes, Spring does provide a pooling capability through its AOP framework. In broad terms, you configure a ProxyBeanFactory in your application context. The "target" bean of the bean factory is actually a pool of beans (the size of which you can of course configure). Whenever a bean of this type is request from the application context, an instance of one of the pooled beans is returned. You can read the official Spring docs on this feature here:

http://www.springframework.org/docs/reference/aop.html#aop-ts-pool

We do not cover the pooling aspect of Spring's AOP in Spring in Action, and here is why. EJBs do offer pooling. You will use these EJBs in your business and persistence layers of your application. In your Spring application, you will likely be using POJOs to provide these same services (with some AOP thrown in to add features like transaction management). However, these objects will most likely be stateless and threadsade, so pooling is not necessary. You can simply creater singleton Spring beans.

The best pooling scenario we could come up with was connection pooling. This feature is already available through other means, so we opted to leave the pooling feature out of the book - to complex of a topic for too infrequent of a use case.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Thanks. Where can I find the Table of Contents of the book.
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
You can find the ToC here:

http://www.manning.com/catalog/view.php?book=walls2&item=contents
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Thanks Ryan. How does Spring compare with other Ioc frameworks?
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
Hi,
Is it mentioned somewhere, how to use Hibernate along with the Spring, in the book ? (I could't find it in the index.).

I hope like the other "In Action Series" books, there will be some working example followed by the concept, just touched upon.


"Ignorance is bliss"
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Originally posted by Mishra Anshu:
Hi,
Is it mentioned somewhere, how to use Hibernate along with the Spring, in the book ? (I could't find it in the index.).

I hope like the other "In Action Series" books, there will be some working example followed by the concept, just touched upon.


http://www.manning.com/catalog/view.php?book=walls2&item=contents

See 4.4 in the link above
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
:roll:

Got it. What about the examples followed by the concept?
I think it must be there.
angelo celeste
Ranch Hand

Joined: Mar 21, 2001
Posts: 73
Hi Mishra.
Try this:
http://www.manning.com/catalog/view.php?book=walls2&item=source
[ April 14, 2005: Message edited by: angelo celeste ]
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Originally posted by Mishra Anshu:
Hi,
Is it mentioned somewhere, how to use Hibernate along with the Spring, in the book ? (I could't find it in the index.).

I hope like the other "In Action Series" books, there will be some working example followed by the concept, just touched upon.


Yep. As Ryan just said, Hibernate integration with Spring is pretty easy.
The book seems to cover this in less than 5 pages.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Srikanth Shenoy:


Yep. As Ryan just said, Hibernate integration with Spring is pretty easy.
The book seems to cover this in less than 5 pages.


As Ryan mentioned in another topic, Hibernate integration is very straight forward. You declare a session factory bean, then write DAO objects that extend HibernateDaoSupport. In each of your DAO methods, you write code something like this:




And that's it.

The magic is behind the getHibernateTemplate() method. The Hibernate template looks like a Hibernate session (as far as you DAO is concerned), but it hides the need to deal with HibernateExceptions and it also has hooks into Spring's declarative transaction support.
 
jQuery in Action, 2nd edition
 
subject: To authors