The Artima Developer Community
Sponsored Link

Java Community News
Spring and EJB 3 Comparative Analysis

1 reply on 1 page. Most recent reply: Nov 9, 2007 11:42 PM by David Eriksson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Spring and EJB 3 Comparative Analysis Posted: Nov 9, 2007 5:11 PM
Reply to this message Reply
In a recent article-length blog post, Interface 21's Mark Fisher provides a detailed comparison of the two Java enterprise frameworks.

Stating that,

Many Java developers are overwhelmed by the vast number of options today ... it's important that they have all of the facts necessary to make well-informed decisions

Interface 21's Mark Fisher proceeds to dispel a few common misunderstandings about how Spring compares with EJB3. While Spring is sometimes presented as a competitor to Java EE and the EJB standard, Fisher notes that:

Spring and EJB 3 need not be mutually exclusive. Spring can be used within EJB applications, EJBs can be accessed from Spring applications, and Spring now supports most of the same annotations...

One of main misunderstandings about Spring, according to Fisher, is that is requires more configuration than the annotation-based EJB 3, and that Spring configuration favors XML over annotations. Fisher, a principal author of the Spring annotation framework, comments that:

I must say that the Spring metadata model is extremely flexible and therefore we have been able to provide a comprehensive annotation-based model more quickly than one might expect. In fact, Spring 2.5 provides support for JSR-250 annotations: @Resource, @PostConstruct, and @PreDestroy - as well as @WebServiceRef and @EJB. Of particular interest is @Resource since it is the primary annotation used for dependency injection in EJB 3...

Spring 2.0 also introduced full annotation-based AspectJ support ... and the concept of "stereotype" annotations. For example, the @Repository annotation enables non-invasive Exception translation for data-access code that uses JPA or Hibernate APIs directly (without Spring's templates)...

Fisher also points out the relatively quick turn-around time for Spring-based development, primarily by reducing the time a developer spends deploying an application in an app server.

In reality, having to deploy to an Application Server during each development and testing cycle is a major obstacle to agility. Typically Spring users will modularize their configuration such that "infrastructure" configuration... is separate and dynamic properties are externalized...

In addition, Fisher notes that Spring offers developers a choice between various persistence APIs, such as those of Hibernate, in addition to JPA:

If you do want to use the Hibernate API directly instead of relying on the JPA API, Spring enables that, and it does so in a consistent way with regard to Spring transaction management and Exception translation. This then opens up the opportunity to use Hibernate features that extend beyond the limitations of JPA, such as Hibernate's "criteria" query API. By the same token, if you would like to add some direct JDBC for data-access where ORM is overkill, that is also supported in Spring - even when invoked within the same transaction as Hibernate or JPA data-access.

Another point Fisher brings up is Spring's auto-detection capabilities that help reduce the need for explicit configuration:

These techniques of "auto-detection" and "intelligent defaulting" apply throughout Spring, such as the JMS 'connectionFactory' for a message-listener (which is implicit in the example of #6 below) and the automatic location of an existing MBean server or RMI registry.

Other issues Fisher discusses include Spring's support for AOP in specifying interceptors, and light-weight transaction management.

How does EJB 3 and Spring compare in your experience?

David Eriksson

Posts: 13
Nickname: twogood
Registered: Apr, 2005

Re: Spring and EJB 3 Comparative Analysis Posted: Nov 9, 2007 11:42 PM
Reply to this message Reply
A link to by Mark's article maybe? :-)

Flat View: This topic has 1 reply on 1 page
Topic: Douglas Crockford on The State of Ajax Previous Topic   Next Topic Topic: Chet Haase Releases Animated Transitions Library for Swing

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use