Bonjour,
j'ai un petit souci sous un serveur GlassFish.
Je suis en train de lire un livre qui s'appelle EJB3 in action et j'aurai voulu une petite web-app pour faire un exemple réaliste.
Donc j'ai crée un projet EAR qui m'a crée un projet WAR et un autre.
Dans le war j'ai développé une petite interface sous Struts.
A partir d'une action j'appelle un EJB qui est injecté par dépendance.
Or l'injection ne doit pas marche je me retoure avec des NullPointerException à chaque fois. Mon code est ci dessous :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 java.lang.NullPointerException at org.bidool.EJBExample.Action.BidValidationAction.execute(BidValidationAction.java:43)
J'ai aussi remarque une autre exception mais au lancement du serveur
-----------------------------------------------------
Mon action
-----------------------------------------------------
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 public class BidValidationAction extends Action{ @EJB private static PlaceBid placeBid; @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("------------------------ Tralalala" ); FormBIDEntry formulaire = (FormBIDEntry) form; try{ Bid bid = new Bid(); bid.setBidAmount(Integer.parseInt(formulaire.getAmount() )); bid.setBidderID(Integer.parseInt(formulaire.getBidderID() )); bid.setItemID(Integer.parseInt(formulaire.getItemID() )); placeBid.addBid(bid); // ca foire ici }catch ( Exception e) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date date = sdf.parse("17/04/1979"); System.out.println("------------------------ Yop : " + date.toString()); e.printStackTrace(); } return mapping.findForward("success"); } }
Ma business interface
-----------------------------------------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 @Local public interface PlaceBid { public Bid addBid(Bid bid); }
Mon implementation de Bean.
-----------------------------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 @Stateful public class PlaceBidBean implements PlaceBid { // Add business logic below. (Right-click in editor and choose // "Insert Code > Add Business Method" or "Web Service > Add Operation") @Override public Bid addBid(Bid bid) { System.out.println(bid); return bid; } }
Cordialement.
AbdouPoulou
Partager