欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

glassfish客户端调用ejb 博客分类: EJB EJBGlassfishJavaSUN 

程序员文章站 2024-03-21 09:33:46
...

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