This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
could someone help me in choosing ejb3 vs spring. I know both can be used for business layer, easy integration with hibernate/jdbc etc. I know ejb is a specification, spring is not. So, what can be driving force in choosing one?
I think it's much more a matter of taste, great things can be achieved with both, I can't really say that one is best than the other for anything. But I'm saying this because I've JEE6 in mind and not just EJB, the same is valid for Spring.
For simplicity, portability and vendor competition I would go with EJB. But I'm working with Spring and it's pretty cool, so I can't really have a opinion about it.
Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
Just as Jayr said it is much a matter of taste, but there are other consequences as well. Spring is a lightweight framework requiring just a web container. EJB (with the exception of EJB Lite) on the other hand needs application server to offer whole set of functionalities (eg Message Driven Beans, Java Mail and Java Web Services are not available in EJB Lite profile). In my opinion Spring (just as JBoss Seam) are more initiative and introduce concepts that are incorporated into EJB only after a while. However I'm still a big fan of EJBs (and a whole JEE) and encourage to get to know both technologies. It's then a matter of project specification that would help to choose best technology for particular needs.
Spring is a lightweight framework requiring just a web container.
But in most part of the time, you'll see something different. You'll see Spring projects using the same application server that could be used by EJB, that's why everyone wants to enjoy the nice built-in features they offer, and when you use a web container with Spring, it will probably use the same or even less services than an analogous EJB project on top of a lite container.
I really like Spring, but is difficult to say which one is best. And I'll not start to state the benefits of EJB or Spring because this discussion already exists in a lot of places. The tip I can give anyone that wants write a project must think not just on the technology itself, but also on the team that's gonna use it, with all this in mind, you'll surely make the right decision!
My rule of thumb is that one does't use EE technologies as long as there is no real need to use it. Like technical requirement from customer or featureset that obviously would require you to "wire" yourself with application server. As a developer one of the first things to think about is a deploy time and resources consumption of a J2EE Application Server. Most of them will consume lots of resources and take a while to redeploy your application, while you'd like to see how the changed code works right away.
So if you need some simple tasks to be accomplished I'd say you should stick to spring, as servlet container would be lot more responsive to the changes that you make in your code. And servlet container will start\stop faster if you have to switch from one project to another occasionally. And besides spring would actually allow you to switch to EE technologies with few lines of code inserted, once you need them. So the approach is scalable. Start with spring - move to EE when needed.
Just as everyone said - do whatever suits you and whatever is simplier in your case :-)
I'd just like to mention that with Java EE 6 AS (Glassfish, JBoss AS7, Resin Caucho, ...) the deployment is really easy and fast -- just take a look at the numbers.
I would say after Marcin that the best is to know both technologies, test them and then choose the right one. One of the worst thing to do is to run to Spring because someone, somewhere said that EJB / Java EE is too overweight. It's very often heard argument which was valid in J2EE 1.4 era not in Java EE 6.