Exceção no EJB session stateful

obrigado pela dica Paulo

Olá a todos pessoal,

estou entrando agora na lista e já com uma dúvida…

Estou com um exemplo EJB Session Stateful que não consigo executar

Está dando a seguinte exceção:

javax.naming.NamingException: Error instantiating web-app JNDI-context: No location specified and no suitable instance of the type ‘cart_session.Cart’ found for the ejb-ref ejb/CartHome

Segue o código:

[code]-- BEAN
package cart_session;

import javax.ejb.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/* the bean class itself */
public class CartBean implements SessionBean {
SessionContext sessionContext;
java.lang.String _cardHolderName;
java.lang.String _creditCardNumber;
java.util.Date _expirationDate;
java.util.List _items = new ArrayList(10);

public void ejbCreate(String cardHolderName, String creditCardNumber, Date expirationDate) throws CreateException {
/**@todo Complete this method*/
this._cardHolderName = cardHolderName;
this._creditCardNumber = creditCardNumber;
this._expirationDate = expirationDate;
}

public void ejbRemove() {
/@todo Complete this method*/
}
public void ejbActivate() {
/
@todo Complete this method*/
}
public void ejbPassivate() {
/@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public void addItem(Item item) {
/
@todo Complete this method*/
System.out.println("\taddItem(" + item.getTitle() + "): " + this);
this._items.add(item);
}

public void removeItem(Item item) {
/**@todo Complete this method*/
System.out.println("\tremoveItem(" + item.getTitle() + "): " + this);
if (! _items.remove(item)) {
throw new EJBException("The item " + item.getTitle() + " is not in your cart.");
}
}

public java.util.List getContents() {
/**@todo Complete this method*/
System.out.println("\tgetContents(): " + this);
return _items;
}

public float getTotalPrice() {
/**@todo Complete this method*/
System.out.println("\tgetTotalPrice(): " + this);
float totalPrice = 0f;
for (int i = 0, n = _items.size(); i < n; i++) {
Item current = (Item) _items.get(i);
totalPrice += current.getPrice();
}
return ( (long) (totalPrice * 100)) / 100f;
}

public void purchase() {
/**@todo Complete this method*/
System.out.println("\tpurchase(): " + this);
Date today = new Date();
if (_expirationDate.before(today)) {
throw new EJBException("Expiration date: " + _expirationDate);
}
System.out.println("\tPurchasing not implemented yet!");
}
}
[/code]


  --INTERFACE REMOTA
package cart_session;

import javax.ejb.*;
import java.util.*;
import java.rmi.*;


/* the bean?s REMOTE INTERFACE */

public interface Cart extends javax.ejb.EJBObject &#123;

  public void addItem&#40;Item item&#41; throws RemoteException;
  public void removeItem&#40;Item item&#41; throws RemoteException;
  public java.util.List getContents&#40;&#41; throws RemoteException;
  public float getTotalPrice&#40;&#41; throws RemoteException;
  public void purchase&#40;&#41; throws RemoteException;

&#125;
  --INTERFACE HOME
package cart_session;

import javax.ejb.*;
import java.util.*;
import java.rmi.*;

/* the bean?s HOME INTERFACE */

public interface CartHome extends javax.ejb.EJBHome &#123;

  public Cart create&#40;String cardHolderName, String creditCardNumber, Date expirationDate&#41; throws CreateException, RemoteException;

&#125;


  --CHAMADA DO SERVLET
     &#40;...&#41;
     Object obj = null;
     Context context=null;
     String JNDIName = &quot;java&#58;comp/env/ejb/CartHome&quot;;
     Hashtable env = new Hashtable&#40;&#41;;
     env.put&#40;Context.URL_PKG_PREFIXES, &quot;oracle.aurora.jndi&quot;&#41;;
     try &#123;
       // Create Initial Context and look up directory service of OC4J for object
       context= new InitialContext&#40; env &#41;;
       obj = context.lookup&#40;jndiName&#41;;
       cartHome = &#40;CartHome&#41; PortableRemoteObject.narrow&#40;obj, CartHome.class&#41;;
        cartHome.create&#40;&quot;TesteNome&quot;,&quot;99999999-89&quot;, new Date&#40;&#41;&#41;;

     &#125;catch &#40;NamingException e&#41; &#123;
       e.printStackTrace&#40;&#41;;
     &#125;
     &#40;...&#41;
  --WEB.XML
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot; &quot;http&#58;//java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;&gt;
&lt;web-app&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;cartservlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;cart_session.CartServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;cartservlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/cartservlet&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;ejb-ref&gt;
    &lt;ejb-ref-name&gt;ejb/CartHome&lt;/ejb-ref-name&gt;
    &lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt;
    &lt;home&gt;cart_session.CartHome&lt;/home&gt;
    &lt;remote&gt;cart_session.Cart&lt;/remote&gt;
    &lt;!-- &lt;ejb-link&gt;cart_session&lt;/ejb-link&gt; --&gt;
  &lt;/ejb-ref&gt;

obs: estou usando
-Jbuilder 9
-OC4J (container)

obrigado

Zap

Editado para conter BBcode Code por jujo

Bom… se te ajudar…

http://www.oziel.com.br/ebooks.html ai tem um link para de um livro sobre EJB

boa sorte

[color=“darkblue”]Campanha POST > ZERO[/color]