0
votes

I'm trying to achieve this goal: deploy a WAR made of a simple Servlet which does the injection of an EJB, and invoke a business method on it.

All is made using a maven project made by two components:

1) Sample EJB (pom.xml is packaged as ejb) 2) Sample WAR (Servlet, with pom.xml packaged as WAR. Dependency to ejb module)

I would tell first that I'm able to do this exercise in another way, packaging both WAR and EJB inside an EAR, but not the above mentioned one. Anyone can tell me if there is any limitation of the used Application Server (WebLogic 10.3.3)?

Code snippet from SimpleServlet (WAR):

public class SimpleServlet extends HttpServlet {

@EJB(mappedName="ejb/SimpleSessionBean")
private SimpleSessionRemote simpleSessionBean;

Code snippet from SimpleSession Remote Interface (EJB):

@Remote
public interface SimpleSessionRemote
{
    String getMessage();
}

Code snippet from SimpleSession Bean class (EJB):

@Stateless(name="SimpleSessionEJB", mappedName="ejb/SimpleSessionBean")
@Remote(SimpleSessionRemote.class) 
public class SimpleSession
{
...

The EJB doesn't have the weblogic-ejb-jar.xml deployment descriptor, so it is fully annotated EJB.

After deploy of WAR in Admin Console, I get a null reference after the direct injection in the Servlet.

What's wrong? Did I forget any step?

Regards, Pierluigi Salera

=================================

UPDATE: I found the answer myself

It is not possible with App Server not supporting EJB 3.1

Indeed the WebLogic I'm using supports EJB 3.0 as stated here:

http://docs.oracle.com/cd/E14571_01/web.1111/e14529/compatibility.htm

"

WebLogic Server 11g Release 1 (10.3.3) is JEE5 compatible

"

Java EE 5 supports EJB 3.0 as stated here:

http://download.oracle.com/otn-pub/jcp/javaee-5.0-fr-eval-oth-JSpec/javaee-5_0-fr-spec.pdf?AuthParam=1377598866_1774a69dcb8b920f69c0c2623068e247

I have also checked in EJB 3.0 specifications (JSR220), where, actually, it is never explicity mentioned that is not possible to package an ejb inside a .war. The fact this is not supported, I believe, is left as implied.

To provide a complete overview I have finally checked the EJB 3.1 specifications (JSR318) where it is explicity stated that "

Enterprise beans can also be packaged within a web application module (.war)"

, chapter 20 Packaging.

So we can conclude that the scope of my exercise is to demonstrate that packaging of an Enterprise Bean in a WAR is not possible with an Application Server that doesn't support EJB 3.1 specifications.

Kind Regards, Pierluigi Salera

1

1 Answers

2
votes

Servlet 2.5 implies Java EE 5. EJB in WAR is only supported since Java EE 6.

You've 2 options:

  1. Upgrade to a Java EE 6 compatible container.
  2. Stick to Java EE 5 and create an EAR instead of WAR. An EAR can consist of EJB JAR and WAR.

See also: