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