Well, as always with these sorts of open-ended comparisons, it's helpful to try to be specific. EJB3 (and EJB 3.1) provides a component model for services that manipulate state (most of the time using JPA (and JPA2). The component model assumes that you might need to expose your EJBs for remote clients using SOAP or RMI, and it assumes that you might need to have declarative transactions. It assumes you might want to handle JMS messages in a bean, too. It assumes that you are content working in an application server, which doesn't promote unit testing or portable code. That's (broadly speaking) about it.
If you simply want service objects that are able to manipulate JPA state and provide declarative transactions and be exposed as web services, than Spring provides all of that *and* you can unit test it naturally and you enjoy full support for deploying to other environments like clouds and web servers, not just Java EE application servers.
However, Spring is a much, much, much larger superset than EJB. "Spring" also provides batch processing, web frameworks, much stronger RDBMS support - JPA1, JPA2, JDBC, JDO, etc, mobile client support, big data (Neo4j, CouchDB, Riak, Redis, MongoDb, etc.), Hadoop support, and numerous simplifying APIs for other APIs that EJB has no particular support for, including JDBC, iBatis, etc. Technically there is no reason to use EJB3 or EJB3.1, there is nothing that it can do that Spring can't and a whole world of things that Spring can do that EJB (and Java EE6) can't.
Thanks, Josh Long
Spring Developer Advocate, SpringSource, a division of VMware
http://blog.springsource.org - http://www.joshlong.com
Dariusz Skrudlik wrote:I agree that we are able to do almost anything with Spring (and more).
But what about scalability and performance ?
Since your code and application is now POJO, then is Java scalable or performant. It really now comes down to that and not to do with Spring itself. Spring is out there in very large applications, so it is scalable and performant.