Bonjour
J'ai un probleme de Naming que je n'arrive pas à résoudre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 package org.test; import java.util.List; public interface HelloWorldService { public String sayHello(String name); public List<Welcome> findWelcomeHistory(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package org.test; import java.util.List; import javax.ejb.Local; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; @Stateless(mappedName="HelloWorldServiceBean") @Local(HelloWorldService.class) public class HelloWorldServiceBean implements HelloWorldService { @PersistenceContext protected EntityManager manager; @Override public String sayHello(String name) { manager.persist(new Welcome(name)); return "Hello " + name + "!"; } @SuppressWarnings("unchecked") @Override public List<Welcome> findWelcomeHistory() { Query query = manager.createQuery("from " + Welcome.class.getName()); return query.getResultList(); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.test; import javax.naming.InitialContext; import javax.naming.NamingException; public class MainTest { /** * @param args * @throws NamingException */ public static void main(String[] args) throws NamingException { InitialContext ctx = new InitialContext(); HelloWorldServiceBean br = (HelloWorldServiceBean) ctx.lookup("HelloWorldServiceBean"); System.err.println("================================="); System.err.println("EJB message is:" + br.sayHello("Test")); System.err.println("================================="); } }
Ce bout de code me parait simple...est pourtant il me retourne une jolie erreur...pourquoi ? :o
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.test.MainTest.main(MainTest.java:14)
Partager