Problème avec l'interface locale d'un bean
Je travaille sur un projet d'ejb. Le code suivant fonctionne :
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
|
public class TestStudent {
Properties properties;
public TestStudent() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}
public static void main(String[] args) {
TestStudent beanStudent = new TestStudent();
beanStudent.createBean();
}
public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup(StudentHome.JNDI_NAME);
StudentHome studentHome = (StudentHome) PortableRemoteObject.narrow(object,StudentHome.class);
Student student = studentHome.create();
student.setName("pirlouit");
System.out.println(student.getId());
System.out.println(student.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
} |
alors que le code suiant, utilisant l'interface locale du bean ne fonctionne pas :
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
|
public class TestStudent {
Properties properties;
public TestStudent() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}
public static void main(String[] args) {
TestStudent beanStudent = new TestStudent();
beanStudent.createBean();
}
public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup(StudentLocalHome.JNDI_NAME);
StudentLocalHome studentLocalHome = (StudentLocalHome)object;
System.out.println("studentLocalHome is null ? "+studentHome.equals(null));
StudentLocal student = studentLocalHome.create();
student.setName("pirlouit");
System.out.println(student.getId());
System.out.println(student.getName());
} catch (NamingException e) {
throw new EJBException(e);
} /*catch (RemoteException e) {
throw new EJBException(e);
}*/ catch (CreateException e) {
throw new EJBException(e);
}
}
} |
L'affichage me donne true, ce qui signifie que l'objet studentLocalHome est null (là est le problème ...)
qqn sait il ce qui ne va pas dans mon code ?
Merci d'avance