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());
        }
    }
 

你可能感兴趣的:(EJB,Glassfish,Java,SUN)