程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 關於EJB3的一個簡單例子

關於EJB3的一個簡單例子

編輯:關於JAVA

EJB3已經變得很簡單了,在這記上一筆。

關於EJB3,可參閱:http://www.foshanshop.Net/

服務器選擇Jboss。客戶端需要導入Jboss/client/jbossall-clIEnt.jar才能調用發布在Jboss中的EJB。

代碼:

HelloBeanLocal.Java

vIEw plaincopy to clipboardprint?

package session;

import Javax.ejb.Local;

@Local

public interface HelloBeanLocal {

}

package session;

import Javax.ejb.Local;

@Local

public interface HelloBeanLocal {

}

HelloBeanRemote.Java

vIEw plaincopy to clipboardprint?

package session;

import Javax.ejb.Remote;

@Remote

public interface HelloBeanRemote {

public String sayHello(String name);

}

package session;

import Javax.ejb.Remote;

@Remote

public interface HelloBeanRemote {

public String sayHello(String name);

}

HelloBean.Java

vIEw plaincopy to clipboardprint?

package session;

import Javax.ejb.Stateless;

@Stateless

public class HelloBean implements HelloBeanLocal, HelloBeanRemote {

public String sayHello(String name) {

System.out.println("服務器端輸出:" + name);

return "Hello, " + name;

}

}

package session;

import Javax.ejb.Stateless;

@Stateless

public class HelloBean implements HelloBeanLocal, HelloBeanRemote {

public String sayHello(String name) {

System.out.println("服務器端輸出:" + name);

return "Hello, " + name;

}

}

HelloBeanClIEnt.Java

vIEw plaincopy to clipboardprint?

import Java.util.*;

import Javax.naming.*;

public class HelloBeanClIEnt {

public static void main(String[] args)throws Exception {

// Hashtable propertIEs=new Hashtable();

// propertIEs.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

// propertIEs.put(Context.PROVIDER_URL,"jnp://127.0.0.1");

// InitialContext ctx=new Javax.naming.InitialContext(propertIEs);

Properties props = new PropertIEs();

props.setProperty("Java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

props.setProperty("Java.naming.provider.url", "127.0.0.1:1099");

props.setProperty("Java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

InitialContext ctx = new InitialContext(props);

session.HelloBeanRemote remote=(session.HelloBeanRemote)ctx.lookup("HelloBean/remote");

System.out.println(remote.sayHello("Beijing"));

ctx.close();

}

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved