Thursday, December 17, 2009

EJB 3 SessionBeans vs. Spring

SessionBeans provide the following:
  • Instance pooling
  • Automated session state maintenance
  • Passivation/activation
  • Annotations to escape the XML hell(that was EJB2.x).
  • Native integration with JSPs, Servlets, JTA transactions, JMS providers, JAAS, etc being part of J2EE stack.
Spring doesn't have the above which was why those points were highlighted. But Spring is irreplaceable if you need DI into plain Java classes. JdbcTemplate and JmsTemplate are a couple of very important tools in this respect. One area where Spring scores above EJB3 is AOP which is more feature rich than EJB interceptors.