Monday, December 9, 2013

EJB3 vs Spring

After many years happily spent using the Spring framework, I got involved into an EJB-based project, and luckily it was EJB3 based :)
Let's see what are the advantages EJB estimators usually come up with and let's compare them with their Spring equivalent: 
  • Bean life cycle management. Spring's core is all about this
  • Dependency Injection: in an EJB3 you can only inject other EJB's or objects registered in JNDI with relative lookup overhead. With Spring you can inject anything you want, including values coming from properties file, which is very nice
  • Transaction management: really great but Spring fully supports JTA as well
  • Distributed transaction: it can be very handy, but it is also true that a simple design presumes a single database, if you have multiple ones you are probably working on some legacy system
  • Security: it would have been great if it would not depend on the application server vendor and it would not be web dependent (since you have to first authenticate on that layer most of the time). Anyway Spring support the same feature
  • Stateful session bean: I don't plan to use them any time soon :)
  • Thread safe abstraction model: it is nice that as a developer I do not have to care about concurrent access to my bean. However this goal is achieved by maintaining a pool of beans you have to be aware of when you want to tune. Personally I prefer to use not thread safe Spring beans and having total control of what is going on, but this is just my opinion
  • Aspect Oriented Programming: in this case support is quite limited since it is runtime only (Interceptors will contain the aspect's logic). This means you cannot use AspectJ, which is very bad :(
  • Timer: also in this case the support is quite limited, if you want to use any cron-like expression to schedule jobs you would better make use of the Quartz library
  • EJB3 are POJO so they are easy to test, I would say they are easier but not easy to test. Since, as I said before, Dependency Injection support is quite limited, mocking becomes not easy as well. For example, mocking and injecting an EntityManager is not something trivial
  • JMS integration: Message Driven Bean are really great, you can setup something similar with Spring as well, but in this case I would go for EJB
  • JPA: well this is really great but in this case credits go to Hibernate since Entity Beans,JPQL are just clones of Hibernate domain object, HQL and so on
  • Annotation based vs Xml configuration: I prefer EJB in this case too. Anyway the Spring Java Config provides no-xml configuration as well
  • Clustering, load balancing, fail-over: really great but still it's the developer's responsibility to setup a mechanism to allow beans running on different nodes to share their data (Database and Terracottaare the best options for this)
  • Integrated solution stack: this is one of the biggest advantages. In one package you get so many features you would need to refer to many different library(s) to get the same result. Still when you need something more specific (like cron expression for scheduling) you would still need to recur to an external library
  • It is a standard: this can be a pro but a cons at the same time, since being a standard its evolution is quite slow

4 comments:

oakleyses said...

louis vuitton handbags, oakley sunglasses, louboutin, longchamp outlet, nike shoes, louis vuitton outlet stores, chanel handbags, burberry outlet, prada outlet, jordan shoes, tiffany and co, michael kors outlet, tory burch outlet, louis vuitton outlet, longchamp handbags, nike free, true religion jeans, michael kors outlet, kate spade outlet, polo ralph lauren outlet, tiffany and co, prada handbags, polo ralph lauren outlet, michael kors outlet, michael kors outlet, longchamp handbags, oakley sunglasses, ray ban sunglasses, kate spade handbags, burberry outlet, louis vuitton outlet, louboutin outlet, louboutin, coach factory outlet, air max, air max, coach outlet, gucci outlet, christian louboutin shoes, michael kors outlet, coach purses, ray ban sunglasses, michael kors outlet, louis vuitton, coach outlet store online, true religion jeans, oakley sunglasses cheap

oakleyses said...

ralph lauren, lululemon, air max, hollister, north face, nike air max, polo lacoste, vanessa bruno, timberland, vans pas cher, louboutin, louis vuitton, oakley pas cher, air max pas cher, nike roshe run, air max, true religion outlet, barbour, sac longchamp, air force, hollister, sac louis vuitton, nike free, polo ralph lauren, nike trainers, louis vuitton uk, nike roshe, sac hermes, longchamp, michael kors, sac burberry, sac guess, mulberry, new balance pas cher, converse pas cher, sac louis vuitton, hogan outlet, nike tn, north face, true religion outlet, ray ban pas cher, michael kors, air jordan, nike blazer, nike free pas cher, michael kors pas cher, abercrombie and fitch, ray ban sunglasses

oakleyses said...

mac cosmetics, mont blanc, marc jacobs, canada goose outlet, nike huarache, vans shoes, soccer jerseys, hollister, giuseppe zanotti, beats by dre, abercrombie and fitch, longchamp, insanity workout, celine handbags, bottega veneta, ghd, nfl jerseys, north face outlet, chi flat iron, ugg boots, birkin bag, ugg australia, canada goose, herve leger, ugg pas cher, rolex watches, valentino shoes, canada goose uk, canada goose, ferragamo shoes, canada goose, ugg boots, uggs outlet, north face jackets, soccer shoes, asics running shoes, new balance shoes, p90x, lululemon outlet, canada goose jackets, mcm handbags, instyler, babyliss pro, ugg, wedding dresses, jimmy choo outlet, reebok outlet, nike roshe run

oakleyses said...

parajumpers, karen millen, air max, converse, pandora charms, moncler, louboutin, moncler, links of london, lancel, juicy couture outlet, oakley, hollister, pandora charms, supra shoes, thomas sabo, canada goose, gucci, wedding dresses, timberland boots, swarovski crystal, air max, coach outlet store online, moncler, ray ban, canada goose, moncler, ugg, louis vuitton, swarovski, hollister, montre homme, moncler, hollister clothing store, ralph lauren, rolex watches, moncler outlet, moncler, iphone 6 cases, baseball bats, juicy couture outlet, toms shoes, vans, pandora jewelry, ugg, converse shoes