Chapter 11. Spring and EJB

This book has so far focused on Spring as a lightweight container, running in a J2EE application server or outside. We have not yet discussed where EJBs come into the picture. Whether by choice, or for legacy reasons, it may make sense to use Spring in concert with EJBs. This chapter will focus on providing you with the information needed for you to do this in the most effective fashion.

We'll cover:

  • Singleton style access to shared application contexts and bean factories, via Spring's SingletonBeanFactoryLocator and ContextSingletonBeanFactoryLocator. While EJBs have the most use for a mechanism like this, you may come upon other glue code in your application that also has no other way to get to a common Spring container, and needs to use this approach. Even if you do not read the rest of this chapter, it's worth reading this section.

  • Deciding on the actual need for EJBs.

  • Spring's JndiObjectFactoryBean for encapsulating Home object lookup.

  • Spring's local and remote Stateless Session Bean proxies for encapsulating lookup and access of EJB homes and EJB instances, eliminating the need to write EJB API-specific Java code when invoking EJBs.

  • Spring's abstract convenience base classes for implementing EJBs.

  • Some high-level strategies for testing EJBs.

Deciding on the Need for EJBs

Given that you are reading a book on lightweight containers, the first question that probably comes to mind at this point is whether EJBs are even still relevant, with or without Spring. ...

Get Professional Java™ Development with the Spring Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.