[JBoss] javax.naming.NameNotFoundException: PremierEJB3Bean not bound
bonjour,
eclipse WT installé par defaut avec jboss 4.05
Code:
1 2 3 4 5
|
javax.naming.NameNotFoundException: PremierEJB3Bean not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543) |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.et.PremierEJB3;
public class ClientPremierEJB3 {
public static void main(String[] args) {
try {
Context context = new InitialContext();
PremierEJB3 beanRemote = (PremierEJB3)
context.lookup("PremierEJB3Bean/remote");
System.out.println(beanRemote.ditBonjour("ClientPremierEJB3"));
} catch (NamingException e) {
e.printStackTrace();
}
}
} |
je crois que normalement on a pas besoin de definir le jndi.properties puisqu'il est par defaut(sauf erreur)
je l'ai mis quand meme mais il y a un truc etrange
Code:
1 2 3 4
|
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099 |
c'est qu'il met des erreurs sur org.jnp et org et localhost
bon ce n'est peut être rien , en fait je ne sais pas
qu'en pensez vous? ou est l'erreur ?
solution: javax.naming.NameNotFoundException: PremierEJB3Bean not bound
Bonsoir,
le cause de cette exception est dû à la manque de qlq ligne de code qui permettant de configurer le context qui l'utilise l'application pour invoquer l'ejb(Tutorial : développer des EJB 3 avec Eclipse et JBoss).
la solution est de charger les données de fichier jndi.properties dans l'objet context de cette façon
:ccool:
Citation:
public static void main(String[] args) {
try {
Properties _prop = new Properties();
FileInputStream _jndi = new FileInputStream("jndi.properties");
_prop.load(_jndi);
_jndi.close();
Context context = new InitialContext(_prop);
PremierEJB3 beanRemote = (PremierEJB3) context
.lookup("PremierEJB3Bean/remote");
System.out.println(beanRemote.ditBonjour("ClientPremierEJB3"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}
bonne lecture