0

从 jsf 应用程序调用 ejb 时出现以下错误

javax.naming.NamingException: ejb ref resolution error for remote business interfaceretail.ejb.service.CustomerSessionBeanRemote [Root exception is java.lang.ClassNotFoundException: retail.ejb.service.CustomerSessionBeanRemote]

这是下面的代码。

接口:CustomerSessionBean

package retail.ejb.service;

import retail.model.vo.Customer;

public interface CustomerSessionBean {
    public void insterCustomerDetails(Customer customer);

}


package retail.ejb.service;



import javax.ejb.Remote;

import retail.model.vo.Customer;

@Remote
public interface CustomerSessionBeanRemote extends CustomerSessionBean{

    void insterCustomerDetails(Customer customer);


}


package retail.ejb.service;



import javax.ejb.Local;

import retail.model.vo.Customer;

@Local
public interface CustomerSessionBeanLocal extends CustomerSessionBean{
    void insterCustomerDetails(Customer customer);
}


package retail.ejb.service;

import javax.ejb.Stateless;

import retail.model.vo.Customer;

@Stateless(name="CustomerSessionBeanImpl", mappedName="ejb/CustomerSessionBeanImplJNDI") 
public class CustomerSessionBeanImpl implements CustomerSessionBeanRemote,CustomerSessionBeanLocal,CustomerSessionBean{



    @Override
    public void insterCustomerDetails(Customer customer) {
        // TODO Auto-generated method stub
        System.out.println("Customer object ::::" + customer);

    }

}


包retail.web.mbean;

import java.io.Serializable;
import java.util.Properties;

import javax.faces.bean.ManagedBean;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


import retail.ejb.service.CustomerSessionBeanRemote;
import retail.model.vo.Customer;


@ManagedBean
public class CustomerMB implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = -4402277663508618618L;
    private Customer customer = new Customer();
    public void CustomerMB(){
        System.out.println("customer method +++++++++++++++++++++++"+getCustomer());
    }




public Customer getCustomer() {
    return customer;
}



public void setCustomer(Customer customer) {
    this.customer = customer;
}



public String createCustomer() throws NamingException{
    try{
    System.out.println("in Create customer method +++++++++++++++++++++++");
    Properties p = new Properties();
    //properties.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
    p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
    p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
    p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513
    InitialContext c = new InitialContext(p);
    CustomerSessionBeanRemote remote = (CustomerSessionBeanRemote) c.lookup("ejb/CustomerSessionBeanImplJNDI");
    remote.insterCustomerDetails(getCustomer());
    }catch(Exception e){
        e.printStackTrace();
    }
    //System.exit(1);
    return "viewCustomerDetails";
}

}


Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfaceretail.ejb.service.CustomerSessionBeanRemote [Root exception is java.lang.ClassNotFoundException: retail.ejb.service.CustomerSessionBeanRemote]
    at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:433)
    at com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:75)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:556)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:514)
    ... 43 more
Caused by: java.lang.ClassNotFoundException: retail.ejb.service.CustomerSessionBeanRemote
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
    at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:687)
    at com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:462)
    at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:413)
    ... 47 more

请推荐任何人

4

1 回答 1

0

一个可能的原因可能是

EJB 3.0 规范警告Applications that use mappedNames may not be portable 这是在没有映射名称的情况下还是通过查找完全限定的 bean 名称来工作?

您可以在 Glassfish 日志中看到 bean 的可移植名称,请改用该名称。

于 2013-04-25T03:12:33.503 回答