Die zweite JNDI-Suche im folgenden Code schlägt mit einer Ausnahme fehl, wenn sie als eigenständige Anwendung für Glassfish ausgeführt wird (die für die Offenlegung von QueueConnectionFactory
und über JNDI konfiguriert wurde). Der Code funktioniert jedoch einwandfrei, wenn die Zeile jndiContext.close()
entfernt wird.Warum bricht das Aufrufen von close() auf einem InitialContext JNDI für alle zukünftigen Lookups (Glassfish)?
Im echten Code wird der Anruf an close()
von Spring in einem JndiObjectFactoryBean
gemacht, so dass ich es nicht einfach entfernen kann.
Ist das ein Fehler in Glassfish, oder mache ich etwas falsch (z. B. falsche Konfiguration oder falsche Codierung)?
import javax.naming.Context;
import javax.naming.InitialContext;
public class TestInitCtx {
private final static String QUEUE_CONNECTION_FACTORY_JNDI_NAME = "QCF";
private final static String DATA_SOURCE_JNDI_NAME = "DS";
public static void main(String[] args) throws Exception {
Context jndiContext = new InitialContext();
jndiContext.lookup(QUEUE_CONNECTION_FACTORY_JNDI_NAME);
// In Glassfish, this line causes the second lookup
// to throw a com.sun.enterprise.connectors.ConnectorRuntimeException
// (wrapping a NullPointerException)
jndiContext.close();
jndiContext = new InitialContext();
jndiContext.lookup(DATA_SOURCE_JNDI_NAME);
}
}
OK, aber Frühling ruft close() auf den Kontext für mich. Muss ich auf Spring verzichten, wenn mein InitialContext-Objekt eines dieser statischen ist? –