Initial Context > Comment savoir ?
Voilà, mon problème s'est résolu mais je ne sais pas très bien comment alors j'aimerais vous poser la question :
J'avais un code client pour un EJB (EJB sur Weblogic 8.1) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package sb;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.transaction.UserTransaction;
import javax.rmi.PortableRemoteObject;
public class HelloWorldClient {
public static void main(String args[]) {
// Récupération du contexte initial
Context initialContext = null;
try {
initialContext = new InitialContext();
} catch (Exception e) {
System.err.println("Impossible d'accéder au contexte JNDI : " + e);
System.exit(2);
}
// Récupération d'une référence à l'interface locale
HelloWorldHome home = null;
try {
home = (HelloWorldHome)PortableRemoteObject.narrow(initialContext.lookup("myHelloWorld"), HelloWorldHome.class);
} catch (Exception e) {
System.err.println( "Impossible de trouver HelloWorldHome : " + e);
e.printStackTrace();
System.exit(2);
}
// Création d'un objet de même type que l'interafce distante
// et appel de la fonction sayHello()
HelloWorld myHelloWorld = null;
try {
myHelloWorld = home.create();
System.out.println(myHelloWorld.sayHelloWorld());
} catch (Exception e) {
System.err.println("Impossible de créer le bean : " + e);
System.exit(2);
}
}
} |
Et j'avais un message d'erreur. (je vous passe les détails).
En ajoutant ce code ca marche :
Code:
1 2 3 4 5
|
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");
initialContext = new InitialContext(props); |
Mon problème est que je ne sais pas comment cela se fait et surtout comment j'aurais pu savoir qu'il fallait ajouter "weblogic.jndi.WLInitialContextFactory" et surtout "t3://localhost:7001"
Merci pour votre aide