Why doesn't Websphere 9 detect Annotated mappedName value for EJBs?

117 views Asked by At

Following is my Sample Code:

AddStatelessBean.java:

@Stateless(name = "AddStatelessBean", mappedName="ASBean")
@Remote(AddStatelessBean.class)
@LocalBean
public class AddStatelessBeanImpl implements AddStatelessBean {
    public int add(int a, int b) {
        return a + b;
    }
}

My Calling Code: CallAddBean.java:

public static AddStatelessBean getAsbByName() throws Exception {
        Context initialContext = new InitialContext();
        AddStatelessBean asbObj = (AddStatelessBean) initialContext.lookup("ASBean");
        return asbObj;
}

But I get the following error:

javax.naming.NameNotFoundException: Context: VRDWIN7WAS9Node03Cell/nodes/VRDWIN7WAS9Node03/servers/server1, name: ASBean: First component in name ASBean not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]

BUT, if I go to Websphere Admin Console -> Applications -> Websphere Enterprise Applications -> -> EJB JNDI Names and assign the same JNDI name there and try to lookup, it is working.

I don't want to do that extra step or configure any XMLs (ibm-ejb-jar-bnd.xml) for making that happen during App Deployment itself.

How do I make this binding from pure JAVA Code itself? My main motive is to make my code run Server independent.

0

There are 0 answers