Spring was designed as an alternative to EJB from the start, so the answer, of course, you can use Spring instead of EJB.
If there is an โadvantageโ to using EJB, I would say that it will depend on the skills of your team. If you don't have Spring experience and a lot of EJB experience, then sticking to EJB 3.0 is probably a good move.
Application servers written to support the EJB standard could theoretically be migrated from one compatible Java EE application server to another. But this means that you must stay away from any specific suppliers that block you from one supplier.
Spring is easy to port between application servers (e.g. WebLogic, Tomcat, JBOSS, etc.) because it is independent of them.
However, you are locked out in Spring.
Spring encourages good OO design methods (such as interfaces, layers, problem separation) that benefit any problem they touch, even if you decide to switch to Guice or another DI framework.
Update. This question and answer is five years in 2014. I must say that the world of programming and application development at that time changed a lot.
This is no longer just a choice between Java or C #, Spring or EJB. With vert.x, Java EE can be abandoned altogether. You can write a very scalable, polyglot without an application server.
Update: Now March 2016. Spring Boot offers an even better way to write applications without Java EE application servers. You can create an executable JAR and run it on the JVM.
I wonder if Oracle will continue to support the Java EE specification. Web services switched to EJB. EJB's decision is dead. (Only my opinion.)
duffymo Nov 22 '09 at 17:13 2009-11-22 17:13
source share