Java Reference
In-Depth Information
Listing 1.1. HelloUser session bean
This listing is a complete and working EJB! The bean class is a POJO , without even
an interface. EJB 3.1 introduced the no-interface view. Before this, EJB required an in-
terface to indicate which methods should be visible. The no-interface view essentially
says that all public methods in your bean will be available for invocation. It's easy to
use, but you need to pick your public methods carefully. The exposeAllTheCom-
panysDirtySecrets() method should probably be private. The funny @Stateless
symbol in listing 1.1 is a metadata annotation that converts the POJO to a full-powered
stateless EJB. In effect, they're “comment-like” configuration information that can be ad-
ded to Java code.
EJB 3 enables you to develop an EJB component using POJOs that know nothing about
platform services. You can apply annotations to these POJOs to add platform services such
as remoteability, web services support, and lifecycle callbacks as needed.
To execute this EJB, you have to deploy it to the EJB container. If you want to execute this
sample, download the actionbazaar-snapshot-2.zip from https://code.google.com/p/action-
bazaar/ , extract “chapter1 project” to build, and install it using Maven and the embedded
GlassFish server.
We're going to analyze a lot of code in this topic—some just as easy as this. You could
trigger the hello as a web service by simply adding the @WebService annotation. You
could inject a resource, like a helper bean that will translate hello into foreign languages,
with @Inject . What do you want to do with EJB? If you keep reading, we'll probably
tell you how to do it.
 
Search WWH ::




Custom Search