I've just created a simple Enterprise Application Project in Eclipse with web module and EJB3 module.
This is my EJB:
@Stateless
public class MyBean implements MyBeanRemote {
public String getGreeting(){return "Hello World!";}
}
This is my Remote Business Interface:
@Remote
public interface MyBeanRemote {
String getGreeting();
}
This is my Servlet:
@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MyBeanRemote myBean = null;
try {
myBean=(MyBeanRemote) new InitialContext().lookup("XXX"); //1
} catch (NamingException e) {e.printStackTrace();}
response.getWriter().append(myBean.getGreeting());
}
}
Bean injection works like a charm, but I'm not being able to successfully perform a JDNI lookup: what should be inserted at line //1
instead of XXX
? I've tried any possible combination (well, clearly missing the right one...)
As far as I understand, Geronimo uses OpenEJB to map name to resources, and at this page you can read that
The default JNDI name is in the following format:
{deploymentId}{interfaceType.annotationName}
so I thought it was just MyBeanRemote
, but that's not working... What am I missing? I've spent my last hours with unsuccessful attempts and reading similar answers here on SO.
This is my openejb.jar.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ejb:openejb-jar xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
<dep:environment>
<dep:moduleId>
<dep:groupId>default</dep:groupId>
<dep:artifactId>MyProjectEJB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
</dep:environment>
</ejb:openejb-jar>
as created by the wizard.