[Servlet][EJB3] deploiement d'un EJB
Bonsoir j'essaye en vain d'utiliser un EJB a partir de ma servlet. Voici mes fichiers sources:
coté ejb :
Code:
1 2 3 4 5 6 7 8 9 10 11
| package com.et;
import java.util.List;
import javax.ejb.Remote;
@Remote
public interface GestionDeStock {
public void ajouter(Produits produit);
public Produits rechercherProduit(String id);
public List<Produits> listerTousLesProduits();
} |
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
| package com.et;
import java.util.List;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class GestionDeStockBean implements GestionDeStock {
@PersistenceContext
EntityManager em;
public void ajouter(Produits produit) {
em.persist(produit);
}
public Produits rechercherProduit(String id) {
return em.find(Produits.class, id);
}
public List<Produits> listerTousLesProduits() {
return em.createQuery("SELECT p FROM Produit p ORDER BY p.quantiteEnStock").getResultList();
}
} |
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 46 47 48 49 50 51 52 53
| package com.et;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Produits implements Serializable {
@Id
private String id;
private String libelle;
private int quantiteEnStock;
public Produits() {
super();
}
public Produits(String id) {
this.id = id;
}
public Produits(String id, String libelle, int quantiteEnStock) {
this.id = id;
this.libelle = libelle;
this.quantiteEnStock = quantiteEnStock;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public int getQuantiteEnStock() {
return quantiteEnStock;
}
public void setQuantiteEnStock(int quantiteEnStock) {
this.quantiteEnStock = quantiteEnStock;
}
public String getId() {
return id;
}
public String toString() {
return "Produit n°" + id + " - " + libelle + " - quantité disponible : " + quantiteEnStock;
}
} |
Partie du code de la servlet :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| try {
Context context = new InitialContext();
GestionDeStock stock;
stock = (GestionDeStock)context.lookup("projetGPS/GestionDeStockBean/remote");
stock.ajouter(new Produits("000", "45297",18));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} |
Voici la stacktrace
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
| javax.ejb.EJBException: java.lang.IllegalArgumentException: Wrong target. class com.et.GestionDeStockBean for public void com.et.GestionDeStockBean.ajouter(com.et.Produits)
org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:58)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
$Proxy307.ajouter(Unknown Source)
com.projet.servlet.servletGestionSession.doCreerCompte(servletGestionSession.java:134)
com.projet.servlet.servletGestionSession.doGet(servletGestionSession.java:53)
com.projet.servlet.servletGestionSession.doPost(servletGestionSession.java:76)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) |
Merci d'avance de votre aide. Si j'ai oublié des éléments hesitez pas à me le demander. Je debute dans l'univers jee EJB ... :)