salut,
j'ai développé un exemple du tuto de Mr TAHE concernant jEE5 sur netbeans, mais dans la partie JBOSS, au moment de lancer l'appli, j'ai une erreur javax.naming.NameNotFoundException: EmployeDao not bound.
le projet est une appli de gestion de salaires, utilisant des classes JPA, une couche DAO(des stateless), et une classe de test (pour tester la couche DAO).
voici une des classes DOA à part le début je pense que c'est pas très intéressant pour résoudre l'erreur)
et voici ma classe de tests:
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 package dao; import exception.PamException; import java.io.Serializable; import java.util.List; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import javax.ejb.TransactionAttributeType; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.PersistenceContext; import jpa.Employe; /** * * @author oliviersaint-eve */ @Stateless @TransactionAttribute(TransactionAttributeType.REQUIRED) public class EmployeDao implements IEmployeDaoLocal,IEmployeDaoRemote ,Serializable{ EntityManagerFactory emf; EntityManager em; public EntityManagerFactory getEmf() { return emf; } public void setEmf(EntityManagerFactory emf) { this.emf = emf; } public Employe create(Employe employe) { em=emf.createEntityManager(); EntityTransaction tx=em.getTransaction(); try{ tx.begin(); em.persist(employe); tx.commit();; }catch (Exception e){ tx.rollback(); throw new PamException("erreur dans employeDao - create / "+e.getMessage(), 1); } return employe; } public Employe edit(Employe employe) { em=emf.createEntityManager(); EntityTransaction tx=em.getTransaction(); try{ tx.begin(); employe=em.merge(employe); tx.commit();; }catch (Exception e){ tx.rollback(); throw new PamException("erreur dans employeDao - edit / "+e.getMessage(), 1); } return employe; } public void destroy(Employe employe) { em=emf.createEntityManager(); EntityTransaction tx=em.getTransaction(); String indice=employe.getId(); Employe employeA=em.find(employe.getClass(), indice); try{ tx.begin(); em.remove(employeA); tx.commit(); }catch (Exception e){ tx.rollback(); throw new PamException("erreur dans employeDao - destroy / "+e.getMessage(), 1); } } public Employe find(String id) { em=emf.createEntityManager(); Employe employe=em.find(Employe.class, id); if (employe==null){ //throw new PamException("erreur dans employeDao - find / aucun employe d'id "+id,1); return null; } return employe; } public List<Employe> findAll() { em=emf.createEntityManager(); return em.createQuery("select e from Employe e").getResultList(); } }
dans la partie "instanciation de la couche DAO" je ne sais pas trop quoi mettre, pouvez-vous m'aider?
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 package daoJboss; import dao.ICotisationDaoLocal; import dao.IEmployeDaoLocal; import dao.IIndemniteDaoLocal; import java.io.File; import java.util.Enumeration; import javax.naming.InitialContext; import javax.naming.NamingException; import jpa.Cotisation; import jpa.Employe; import jpa.Indemnite; import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; /** * * @author oliviersaint-eve */ public class monTestJBoss { private static IEmployeDaoLocal employeDao = null; private static IIndemniteDaoLocal indemniteDao = null; private static ICotisationDaoLocal cotisationDao = null; public static void main(String[] args) throws NamingException { //démarrage EJB3 EJB3StandaloneBootstrap.boot(null); EJB3StandaloneBootstrap.deployXmlResource("META-INF/jboss-config.xml"); EJB3StandaloneBootstrap.scanClasspath("bin".replace("/", File.separator)); // init du ctx JNDI InitialContext initialContext = new InitialContext(); java.util.Hashtable<?, ?> ht = initialContext.getEnvironment(); for (Enumeration<?> e = ht.elements(); e.hasMoreElements();) { System.out.println(e.nextElement()); } //instanciation couche DAO //employeDao = (IEmployeDaoLocal) initialContext.lookup("projet_pam_hib_jboss/EmployeDao/local"); employeDao = (IEmployeDaoLocal) initialContext.lookup("EmployeDao/local"); indemniteDao = (IIndemniteDaoLocal) initialContext.lookup("dao.IndemniteDao"); cotisationDao = (ICotisationDaoLocal) initialContext.lookup("dao.CotisationDao"); //vidage base + remplissage for (Employe employe : employeDao.findAll()) { employeDao.destroy(employe); } for (Cotisation cotisation : cotisationDao.findAll()) { cotisationDao.destroy(cotisation); } for (Indemnite indemnite : indemniteDao.findAll()) { indemniteDao.destroy(indemnite); } Indemnite ind1 = indemniteDao.create(new Indemnite(1L, 1.93, 2, 3, 12)); Indemnite ind2 = indemniteDao.create(new Indemnite(2L, 2.1, 2.1, 3.1, 15)); Employe employe2 = employeDao.create(new Employe("254104940426058", "Jouveinal", "Marie", "5 rue oiseaux", "St Corentin", 49203, ind2)); Employe employe1 = employeDao.create(new Employe("260124402111742", "Laverti", "Justine", "Lades brûlerie", "St Marcel", 49014, ind1)); Cotisation cotisation1 = cotisationDao.create(new Cotisation(3.49, 6.15, 9.39, 7.88)); //le test System.out.println("Employes ---------------------"); for (Employe employe : employeDao.findAll()){ System.out.println(employe); } System.out.println("Indemnités -------------------"); for (Indemnite indemnite : indemniteDao.findAll()){ System.out.println(indemnite); } System.out.println("Cotisations ------------------"); for (Cotisation cotisation : cotisationDao.findAll()){ System.out.println(cotisation); } //after EJB3StandaloneBootstrap.shutdown(); } }
pour jboss, j'ai inclus les jars fournis avec le tuto, mais je n'ai pas défini de serveur jboss dans netbeans, donc du coup je crois que mon serveur jboss se ferme tout de suite après le programme, donc je ne peux pas accéder à la page d'administration du serveur pour regarder les noms jndi.
voici l'erreur:
je précise que le projet a été obtenu par la copie d'un projet spring (qui faisait le même chose), donc jboss n'y est pas lié "nativement"(quand je lance le projet, jboss n'est pas démarré dans netbeans).init:
deps-jar:
compile:
compile-test-single:
run-test-with-main:
org.jnp.interfaces.LocalOnlyContextFactory
org.jboss.naming:org.jnp.interfaces
Exception in thread "main" javax.naming.NameNotFoundException: EmployeDao 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)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at daoJboss.monTestJBoss.main(monTestJBoss.java:49)
Java Result: 1
merci,
olivier.
Partager