The following sample demonstrates injection of an EJB into a servlet and provides an application consisting of a servlet and stateless session bean.
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 184.108.40.206 and later.
To run the EJBSample application:
- Extract the sample into the Liberty installation by running the command below from the root of your server installation:
java -jar EJBSample.jar
- Start the EJBSample server by running the command below from the
bindirectory in the Liberty profile installation:
server run EJBSample
- Confirm the application started by looking for the following message in the log:
CWWKZ0001I: Application EJBSample started in XX.XX seconds.
- In your browser, enter the URL for the application: http://localhost:9132/EJBApp/sampleServlet (where 9132 is the default HTTP endpoint).
- In your browser, you should see the message "Hello EJB World".
- 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.
- - wlp
- - usr
- - servers
- - EJBSample
- - dropins
- - EJBApp.ear
- - server.xml
- - readme.html
- - Copyright.txt