0

I intend to develop and deploy a simple web application using

  1. EJB 3
  2. JSP and servlet
  3. JBoss 7
  4. JPA

I have coded the application and created a standard ear with following structure

app.ear

|_ lib (with all required jars such as the commons logging)

|_ META-INF

   |_ application.xml

   |_ jboss-app.xml

|_ app_ejb.jar (contains a stateless EJB, an entity, persistence.xml etc...)

|_ app_web.war (jsps, servlet, web.xml etc..)

jboss-app.xml :- (library is the app name)

<!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
    <loader-repository>library:app=ejb3</loader-repository>
</jboss-app>

application.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">

<display-name>library</display-name>

<module>
  <ejb>ejb_library.jar</ejb>
</module>

<module>
    <web>
        <web-uri>web_library.war</web-uri>
        <context-root>web_library</context-root>
    </web>
</module>

</application>

Now when I deploy this ear with the admin console of JBoss 7, the web module seems to have been deployed, even the pages are hit. However, the further part of the application where I try to inject the EJB in the servlet (as a instance varialbe using @EJB), fails.

There seems to be some problem in the way I am deploying the application.

I tried to find a tutorial where I could deploy the app in JBoss but with all that I am stuck till this.

Could anyone guide me with this? I am using JBoss for the first time and am not completely aware of JBoss specific configurations.

Upen
  • 1
  • 1
  • 2

1 Answers1

0

EJB that you are injecting, is it implementing an interface? and is that interface registered with the server? @Local or @Remote.

If not, then Try introducing a @Local interface and then your EJB implementation implementing that interface; and then, use that local interface to inject the EJB implementation.

Also, check the threads below;

JBoss 6: Injecting EJB into servlet

Inject an EJB into JAX-RS (RESTful service)

http://docs.jboss.org/ejb3/docs/tutorial/1.0.0/html/Injecting_EJB_in_Servlets.html

A silly thought, but can you re-arrange the modules declarations in application.xml; bring web modules first and ejb following it.

  • module -> web module
  • module -> ejb module

Moreover, this is also related to your situation: http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s04s02.html

Community
  • 1
  • 1
mhan
  • 373
  • 3
  • 11
  • Hi Nav Khan, Thanks for this reply. I went through the links given by you and found that I had implemented the code in the same way as explained. The only thing that was missing was the interface class name in the @Remote annotation of the Stateless Bean. Inspite of specifying it the bean does not inject in the servlet. Could you think of any issue? – Upen Jun 06 '12 at 09:43
  • Forgot to specify an important point. If the source code of the EJB is provided along with the web war, the EJB is injected successfuly. However, if I provide a client jar with the interface that the bean implements, the EJB is not injected. Is anything wrong with this approach? – Upen Jun 06 '12 at 10:10
  • How did you generate that ear file? did you use eclipse EE application wizard? or you put it together yourself? – mhan Jun 06 '12 at 11:37
  • Also change the Remote to @Local as you are accessing the EJB within the same JVM (simply the same server or container) – mhan Jun 06 '12 at 11:45
  • edited my reply with another thought... just in case if you are still trying to resolve this one – mhan Jun 07 '12 at 10:10