views:

1206

answers:

3

What advantages does EJB have to be stacked with Spring? Why couldn't I just use Spring Entity Manager, Security, and POJOs to do what EJB does?

+2  A: 

They overlap a lot, but still distinguished in some areas. For example Spring is very good in light weight remoting, and have a rich AOP support etc. EJB, on the other hand, is very good in state management (stateful session beans), distributed transactions etc. Spring lacks instance pooling, activation/passivation and all. Also, I found it handy to convert your component into a web service using EJB 3.

Look both as complimentary technologies, to get the most out of them.

Adeel Ansari
Pooling is overrated, now that object creation is so fast. Activation/passivation is unnecessary for POJOs. And try Spring "contract first" web services. Very nice, indeed.
duffymo
+1  A: 

I see them as complementary. In other words, it's not one or the other.

We develop with Spring and all the facilities it offers, and then deploy onto an EJB container. Most of the time however you will not require session beans, servlets will suffice. That's the advantage of Spring.

By developing on top of Spring your application does not depend on any application server. It can practically run stand alone, that means you can run tests without a container (Spring does the transactionalisation and life cycle management for you).

Michael Wiles