Enterprise Java Beans (EJB) Sample

Download

The following sample demonstrates injection of an EJB into a servlet and provides an application consisting of a servlet and stateless session bean.

Description

This sample demonstrates injection of an EJB into a servlet. The application consists of a servlet and stateless session bean. The servlet uses annotations to inject the stateless session bean, and then performs a call on the hello method of the bean.

This sample can be installed onto runtime versions 8.5.5.0 and later.

Instructions

To run the EJBSample application:

  1. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar EJBSample.jar
  2. Start the EJBSample server by running the command below from the bin directory in the Liberty profile installation:
    server run EJBSample
  3. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application EJBSample started in XX.XX seconds.
  4. In your browser, enter the URL for the application: http://localhost:9132/EJBApp/sampleServlet (where 9132 is the default HTTP endpoint).
  5. In your browser, you should see the message "Hello EJB World".

Notes

  • The application is automatically installed because it is located in the server dropins directory. Any number of applications can be installed from this location.
  • Source code for the application can be found in the application’s EAR file, located in the EJBSample/dropins folder.

Sample Structure

    • - wlp
      • - usr
        • - servers
          • - EJBSample
            • - dropins
              • - EJBApp.ear
            • - server.xml
            • - readme.html
            • - Copyright.txt