What features does EJB3 bring and also how does EJB3 stack up with the Spring Framework? [closed]
Asked Answered
B

3

6

I have never worked on ejb, when I started programming Spring was already arrived and all my projects have been with Spring only, recently I had one interview and they wanted knowledge of EJB3.0 and so I want to know how does EJB3.0 stack up with Spring Framework and why many projects nowadays are with Spring Framework and not with EJB3.0, do not quote me here as I can be wrong

I would really appreciate if difference and benefits of using one over another could be explained from practical perspective.

Note Please do not give wiki links as answer as I want to understand actually how both this technology stack up.

Update Also what would be best way to start learning for EJB3, what are the recommended Books, Online Tutorial for the same ?

Bus answered 22/12, 2010 at 22:48 Comment(0)
G
10

EJB is a quite old technology (ca. 1999). However, until Version 3 of the standard, it was horribly inconvenient to use. Spring became popular as a sane alternative that offered some of the same core features (declarative transactions and security) as well as some new ones (dependency injection, AOP). It also integrated well with many other technologies such as Hibernate.

However, starting with V3.0, EJBs (or rather, the whole Java EE platform of which EJBs are a part) got a major overhaul and became much easier to use. Additionally, a lot of features made popular by various frameworks (including Spring) were made into official standards and added to Java EE.

Right now, the Java EE platform is gaining a lot of ground vs. Spring in terms of popularity, since they're about even in ease of use and features, and Java EE has the advantage of being based on open standards with multiple implementations for most component. At the same time, it seems to me Spring is having problems keeping up with the state of the art when it comes to integrating with other frameworks (which used to be its strength).

Geotectonic answered 22/12, 2010 at 23:23 Comment(7)
so how is dependency injection done in EJB3, actually am trying to compare EJB3 with Spring to see if I can find common ground between both stack and some ground knowledge which would help me to start understanding EJB3 technologyBus
@Rachel: EJB3 dpendency injection is annotation-based, with XML configuration as a fallback. It uses the JSR-250 annotations and some EJB-specific ones. Actually, almost everything in EJB3 is annotation-based with XML configuration as a fallback. I believe it was inspired by Spring in this, so it should be quite familiar.Geotectonic
Would you mind elaborating on what you mean by "it seems to me Spring is having problems keeping up with the state of the art when it comes to integrating with other frameworks?" This is a very general statement, what specifically has given you this impression?Blondy
@kdonald: for example, the latest Spring release integrates per default with Hibernate 3.3.1 - which is over 2 years old.Geotectonic
@kdonald: That's the problem with the "we'll do the integration for you" approach of Spring - it leads straight into an update treadmill. The Java EE approach is "let's define a standard and integrate by sticking to the standard API" - which not everyone can do and leads to its own constraints, but is definitely more scalable.Geotectonic
The versions of the 3rd-party tools Spring itself compiles against are typically the minimum versions supported by the framework. Spring works fine with the newer versions as well, and does not mandate which version you must use. I happen to be using Hibernate 3.6, and that's my choice as an application developer. I don't think you really get Spring.Blondy
@MichaelBorgwardtthere the question also asked for " Also what would be best way to start learning for EJB3, what are the recommended Books, Online Tutorial for the same ?". Can you recommend the book or the resource that helped you the most as far as EJB 3 is concerned?Engelhart
F
5

I would say the only major difference is Java EE 5 and 6 are a standard. It's taken the ideas of Spring and others and created a standard out of them. Compared to the old EJBs, EJB3 is night and day. All your EJBs are POJOs and dependencies are injected by the container. Gone are all those different interfaces and creating instances manually from the home interface. It will take you maybe couple hours at most to learn if you've already done a lot with Spring. You'll also want to look at JSF if you're doing web applications.

I never did a real application with the old EJBs because it was such a pain. EJB3 I use all the time as it's effortless. If you want to try the newest everything, get a copy of glassfish which I think is still the only Java EE 6 certified server.

Farra answered 22/12, 2010 at 23:16 Comment(4)
So will not having known or worked with EJB in any way affect learning EJB 3 ?Bus
try not to use jsf if you can. there is very little standard about it nowadays and you end up in an impl lock-in.Shreve
@Steven: can you be more specific? I'm starting a JSF project right now, and it seems to me the basic JSF implementation is standardized and implemented as such very well. It's true that the component libraries try to distinguish themselves with new features and using those of course ties you to that library.Geotectonic
I would say not having used the old EJBs will help in learning EJB3. It's completely different so trying to see how it relates to the old stuff would just slow you down.Farra
R
1

In terms of both dependency injection and MVC architectures, Spring had the edge over Java EE 5 in terms of flexibility and ease of use, although as others have said, Java EE 5 (EJB3) was a huge improvement over previous versions of Java EE/EJB. With Java EE 6 I believe Java EE has leapt ahead of Spring in both DI w/ the new CDI (JSR-299) implementation, and in MVC w/ JSF 2.0.

The Oracle online tutorials are rudimentary, but a good starting point for learning Java EE. An excellent resource for learning about DI in Java EE 6 is Reza Rahman's series of articles http://www.theserverside.com/news/1373391/Dependency-Injection-in-Java-EE-6-Part-1

Raber answered 24/12, 2010 at 0:3 Comment(8)
I am not able to understand JEE 6 has leapt ahead with JSF on MVC Architecture ? I have not used JSF in past and so have not clearly understood the point, can you elaborate more explicitly ?Bus
JSF is a component technology so it has in a sense always been a more modern approach than request-driven frameworks like Struts, Spring MVC, etc. But JSF has also been plagued w/ problems from the start - mainly over complexity. With JSF 2.0 they appear to have finally got it right - mainly because they borrowed heavily from Seam. Looking at the JEE6 stack now, it is highly integrated from the data tier through presentation (where they are now using Facelets which is much cleaner than JSP - which is pretty much what you're still stuck w/ on Spring). But JEE6 adoption is going to take time.Raber
Spring supports a variety of view options, including JSP, Freemarker, Velocity, and JSF. The view handling infrastructure is extensible, and you can also plug in your own custom options. You're not stuck with JSP on Spring.Blondy
JSF is not a rendering technology it's an MVC framework. Freemarker and Velocity are simple templating facilities, they're not full-blown rendering technologies like JSP and Facelets. You can use Facelets w/ Spring MVC but that's pretty bleeding edge and there's not much direct support whereas JSF 2.0 was written to integrate w/ Facelets. And if you're going to use JSF 2.0 you'd certainly choose CDI which it was codesigned w/ over Spring DI.Raber
Spring and JSF have worked well together since the JSF 1.0 days, and this continues to be the case with JSF 2.0. The developers I know using JSF 2.0 are using Spring as the managed bean provider, at a minimum. Some of them are also using Web Flow for navigation, and some have plugged Facelets in as a Spring MVC view technology. Primefaces is the most popular JSF 2.0 component library.Blondy
I also would not label JSF as a "more modern" approach than request-driven architectures. "More involved on the server-side" is more accurate. In general, there is a trend towards doing more on the client, and less on the server, and the request-driven frameworks are benefiting from that.Blondy
The developers I know using JSF 2.0 are are all using CDI, none are using Spring. Same w/ Facelets, I only know 2 guys using it but they're both using it w/ JSF. CDI and JSF 2.0 were codesigned and built to target Facelets. It just makes sense.Raber
Obviously we disagree on this and the arguments are starting to repeat.. In the past Spring has both competed with and enhanced JEE technologies. With JEE6 I believe some areas where Spring complemented or beat JEE in the past are now gone. But Spring's business model is to have lots and lots and lots of irons on the fire. They don't care if they win the DI war or the MVC war. There are lots of ways they can win, including completely unique offerings like Roo. There's a dozen plus technologies where their next big hit could come from.Raber

© 2022 - 2024 — McMap. All rights reserved.