Reputation: 65
I am getting a javax.naming.NameNotFoundException: While trying to look up a EJB3 Stateless session bean.
I have 1 weblogic domain and it consists of two servers Server_1 and server_2. I have deployed a EAR file to server_2 which consists of a EJB3 deployment. It has the following inside it
EJB3 EAR file
----EJB3 Module Jar file
------Stateless session EJB3 bean
----META-INF Folder
-- application.xml file
----lib folder
-------EJB3 Client jar holding containing remote and local interface
The EJB3 Module jar file consists of following
EJB3 JAR file
----package structure of EJB3 Stateless bean and bean
----META-INF folder
-----weblogic-ejb-jar.xml
-----ejb-jar.xml.
On server 1 I have deployed my EJB3 Client Jar which has my remote interface inside it. On this server I have also deployed another jar file which will use the remote interface of the client jar to lookup the ejb.
my EJB3 is below
@Remote
public interface ContractorIdRemote {
public String test();
}
@Stateless(name="ContractorIdBean", mappedName="ContractorIdBean")
public class ContractorIdBean implements ContractorIdRemote {
public String test() {
.........
}
}
my ejb-jar file is as follows
<?xml version="1.0" encoding="ASCII"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
<display-name>ejb</display-name>
<enterprise-beans>
<session>
<ejb-name>ContractorIdBean</ejb-name>
<ejb-ref>
<ejb-ref-name>ContractorIdBean</ejb-ref-name>
<remote>com.ejb3.websphere.ContractorIdRemote</remote>
<mapped-name>ContractorIdBean</mapped-name>
</ejb-ref>
</session>
</enterprise-beans>
</ejb-jar>
the weblogic-ejb xml file
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN'
'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ContractorIdBean</ejb-name>
<jndi-name>ejb/ContractorIdBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
My lookup is done as follows from the calling client
Context ctx = new InitialContext(properties);
ContractorIdRemote cRemote = (ContractorIdRemote)ctx.lookup("ejb/ContractorIdBean");
cRemote.test();
my properties file has the following
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:17001
But obviously ejb/ContractorIdBean is not what it is bound with. I can see the EAR is deployed on server_2 successfully
Can anyone please advice what I should use to lookup the ejb. I have tried the following but all with namenotfound exception
java:comp/env/ejb/ejb/ContractorIdBean
java:comp/env/ejb/ContractorIdBean
Thanks in advance
UPDATE:
I changed my jndi name to just contractorIdBean and as before I can see in the jndi tree on the server the binding name ContractorIdBean#com.ejb3.websphere.ContractorIdRemote
But this still throws a Name not found exception
UPDATE AGAIN:
I changed the jndi name to the screenshot above and added the security credentials for the server. Following this I get the following exception now
javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: failed to unmarshal class java.lang.Object; nested exception is:
java.lang.ClassNotFoundException: com.ejb3.websphere.ContractorIdRemote]
I am not sure why it cannot find the class. I have also included it in the deployed EAR file on server_2 as well as in the ejb client jar on server 1
Upvotes: 1
Views: 3861
Reputation: 6227
For a remote lookup (one server to another) you should do something like the following:
Hashtable<String, String> h = new Hashtable<String, String>();
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
InitialContext context = new InitialContext(h);
cId= (ContractorIdRemote) context.lookup("ejb/ContractorIdBean");
Weblogic does not prefix JNDI names with comp/env
so you do not need that. I believe that is used for Tomcat.
Upvotes: 1