glassfish客户端调用ejb

@Stateful
@Remote({UserService.class})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class UserSessionBean implements UserService {

 客户端代码:

   Properties props = new Properties();
        props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
        props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
        props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
        props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");  //host  
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");  //EJB Port  
        try {
            InitialContext ctx = new InitialContext(props);
            UserService userService = (UserService) ctx.lookup("com.byht.evt.user.service.UserService");
            System.out.println(userService.say());
            System.out.println(userService.login(null));
        } catch (NamingException e) {
            System.out.println("error:" + e.getMessage());
        }
    }
 

猜你喜欢

转载自yiyanwan77.iteye.com/blog/1109167