Frage

Ich habe eine EJB wie folgt definiert:

package com.foo;
@Stateless (mappedName="HelloWorld")
public class HelloWorldBean implements HelloWorld, HelloWorldLocal
....

Wenn es um Weblogic (WL) im Einsatz ist, erhält sie den Namen MyBean. Ich bin mir nicht sicher, ob dies ist wichtig.

Ich versuche, mit diesem Code die Bohne zu nennen:

Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(ht);
tp = (HelloWorld) ic.lookup("HelloWorld#com.foo.HelloWorldBean");

Wer weiß, warum ich die folgende Fehlermeldung erhalten?

javax.naming.NameNotFoundException: While trying to lookup 'HelloWorld#com.foo.HelloWorldBean' didn't find subcontext 'HelloWorld#com'.
 Resolved '' [Root exception is javax.naming.NameNotFoundException: While trying
 to lookup 'HelloWorld#com.foo.HelloWorldBean' didn't find
 subcontext 'HelloWorld#com'. Resolved '']; remaining name 'HelloWorld#com/foo/HelloWorldBean'
War es hilfreich?

Lösung

ein Remote Interface einer Session Bean, um die Suche mit mehreren Remote-Business-Schnittstellen (egcom.acme.FooBusiness1, com.acme.FooBusiness2), müssen Sie einen Namen aus der Kombination des globalen JNDI Namen ejb Ziels abgeleiteten Nachschlag (die mappedName() in @Stateless) und die spezifischen Remote-Business-Schnittstelle, getrennt durch einen "#":

InitialContext ic = new InitialContext();
FooBusiness1 bean1 = (FooBusiness1) ic.lookup("FooEJB#com.acme.FooBusiness1");
FooBusiness2 bean2 = (FooBusiness2) ic.lookup("FooEJB#com.acme.FooBusiness2");

Im typischen Fall einer Bohne nur eine Remote-Business-Schnittstelle, diese vollständig qualifizierte Form ist nicht erforderlich. In diesem Fall kann der JNDI Bean Namen direkt verwendet werden:

FooBusiness bean = (FooBusiness) ic.lookup("FooEJB");

Das war der theoretische Teil. Nun ist die Praxis. In Ihrem Fall, von dem, was ich sehen kann, haben Sie die EJB von Weblogic Zugriff auf so würde ich lieber verwenden, um den nicht-arg InitialContext() Konstruktor (und eine jndi.properties Konfigurationsdatei für andere Umgebungen verwenden), aber dies ist nur eine Randnotiz. Dann sollten Sie com.foo.HelloWorld nachschlagen, die Remote Interface, nicht com.foo.HelloWorldBean, die Umsetzung:

InitialContext ic = new InitialContext();
(HelloWorld) ic.lookup("HelloWorld#com.foo.HelloWorld");

Und wenn Ihr Bean nur eine Remote-Business-Schnittstelle hat, sollte diese Arbeit:

(HelloWorld) ic.lookup("HelloWorld");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top