Java Reference
In-Depth Information
Your EJB classes can extend these classes to inherit the methods. Table 5-1 shows Spring's EJB
support classes for different types of EJB.
Table 5-1. Spring's EJB Support Classes for Different Types of EJB
EJB Support Class
EJB Type
Stateless session bean
Stateful session bean
General message-driven bean that may not use JMS
Message-driven bean that uses JMS
Moreover, the EJB support classes provide access to the Spring IoC container for you to implement
your business logic in POJOs and wrap them with EJB components. Because POJOs are easier to develop
and test, implementing business logic in POJOs can accelerate your EJB development. For more on
messaging, please see Chapter 7.
How It Works
Suppose you are going to develop a system for a post office. You are asked to develop a stateless session
bean for calculating postage based on the destination country and the weight. The target runtime
environment is an application server that supports EJB 2.x only, so you have to develop the EJB
component that will work with this version.
Compared with lightweight POJOs, EJB 2.x components are more difficult to build, deploy, and
test. A good practice for developing EJB 2.x components is to implement business logic in POJOs and
then wrap them with EJB components. First, you define the following business interface for postage
public interface PostageService {
public double calculatePostage(String country, double weight);
Then you have to implement this interface. Typically, it should query the database for the postage
and perform some calculation. Here, you may hard-code the result for testing purposes.
public class PostageServiceImpl implements PostageService {
public double calculatePostage(String country, double weight) {
return 1.0;
Search WWH ::

Custom Search