views:

232

answers:

1
+1  Q: 

EJB3 Annotation

Hi All

I am using JBoss 5 GA, I created a test Session bean, and local interface. I have created a servlet client. I tried to inject the interface in the servlet using @EJB..

But when I call this servlet I got the requested resource is not available!!!! When I comment the //@EJB, the page run successfully, any help please????

Jotnarta

+1  A: 

It would have been helpful to add some piece of code in your question, at least the annotations in your EJB, local interface (if you annotated it) and servlet...

Nevertheless, according to the Chapter 11. Introduction to EJB injection in Servlets of the JBoss EJB3 Tutorials, for an EJB module containing an EJB3 SLSB defined like this:

@Stateless(name="calculator")
@Remote(CalculatorRemote.class)
@Local(CalculatorLocal.class)
public class CalculatorBean implements CalculatorRemote, CalculatorLocal
{
...

The local interface can be injected in a Servlet of a web module this way:

private CalculatorLocal calculator;

/**
 * Injecting the EJB
 */
@EJB(name = "calculator")
public void setCalculator(CalculatorLocal calculator)
{
   this.calculator = calculator;
}

There is an important note in this tutorial that i'm pasting below:

For the injection to take place in a web module, your web.xml should use the 2.5 version of the web-app xsd:

<web-app version="2.5"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
Pascal Thivent