自然
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(6)
給我留言
查看公開留言
查看私人留言
隨筆分類
mobile
(rss)
Project Summary
(rss)
隨筆檔案
2012年2月 (2)
2011年2月 (1)
2010年12月 (3)
2010年2月 (1)
2009年7月 (1)
2009年6月 (1)
2009年5月 (1)
2009年4月 (1)
2009年2月 (1)
2008年11月 (3)
2008年7月 (1)
2008年3月 (1)
2008年2月 (1)
2008年1月 (1)
2007年10月 (1)
2007年3月 (2)
文章分類
Architecture(4)
(rss)
bank(6)
(rss)
Class&ClassLoader&-------(8)
(rss)
client&demand(4)
(rss)
Construct(1)
(rss)
DataBase(7)
(rss)
EJB(2)
(rss)
Hibernate(2)
(rss)
integration(2)
(rss)
jar_build_version_and(3)
(rss)
java(2)
(rss)
java glossary(18)
(rss)
job(1)
(rss)
JSF(4)
(rss)
Log(8)
(rss)
mobile
(rss)
OSGI(1)
(rss)
personality(3)
(rss)
Project Summary(5)
(rss)
remote(2)
(rss)
search(3)
(rss)
Server(3)
(rss)
Speak(1)
(rss)
Spring(7)
(rss)
Struts(6)
(rss)
test(2)
(rss)
web(9)
(rss)
感悟(1)
(rss)
錯誤匯總(1)
(rss)
文章檔案
2016年2月 (1)
2015年10月 (1)
2015年5月 (1)
2015年4月 (2)
2015年3月 (5)
2015年2月 (5)
2015年1月 (5)
2011年4月 (1)
2011年2月 (2)
2010年8月 (1)
2010年7月 (1)
2010年6月 (3)
2010年5月 (2)
2010年2月 (1)
2009年7月 (7)
2008年10月 (2)
2008年6月 (3)
2008年5月 (3)
2008年2月 (5)
2008年1月 (2)
2007年12月 (3)
2007年8月 (4)
2007年7月 (5)
2007年6月 (14)
2007年5月 (10)
2007年4月 (16)
2007年3月 (10)
搜索
最新評論
1.?re: Spring 中的數據源
評論內容較長,點擊標題查看
--zuidaima
2.?re: CFCA 數字證書的安裝與使用(轉)
-----------------
--姜艷麗
3.?re: CFCA 數字證書的安裝與使用(轉)
----------
--姜艷麗
4.?re: 怎么變成熟!(轉)
方法:其實成熟說到底是做事和做人,沒什么捷徑可走的, 謝謝字典啊
--吳文興
5.?re: javascript正則表達式對象
不錯
--咱
閱讀排行榜
1.?泰山_歌詞(343)
2.?對象&過程(311)
3.?簡單的道理(299)
4.?我的英語第一次(291)
5.?溫暖的時光(276)
評論排行榜
1.?稻盛箴言(0)
2.?內心語錄(0)
3.?泰山_歌詞(0)
4.?深圳_我的關鍵詞(0)
5.?溫暖的時光(0)
Powered by:
博客園
模板提供:
滬江博客
BlogJava
|
首頁
|
發新隨筆
|
發新文章
|
聯系
|
聚合
|
管理
圖解eclipse+myelcipse開發EJB
圖解eclipse+myelcipse開發EJB
在開發ejb之前,我們先得配置好服務器,我使用的是Weblogic9.0中文版,關于Weblogic9.0配置請看我的另一片文章。
配置Weblogic9.0
首先需要配置好eclipse。我這里主要說明weblogic的配置。
注意JDK選擇JDK5.0的版本。
順便將weblogic8的配置也貼上來,供大家比較參考
注意weblogic8的JDK版本必須是JDK1.4。
接下來就開始我們的開發了。
下面就是SessionBean的代碼
30
1
package
com.ejb;
2
3
import
java.rmi.RemoteException;
4
5
import
javax.ejb.EJBException;
6
import
javax.ejb.SessionBean;
7
import
javax.ejb.SessionContext;
8
9
/**
10
* XDoclet-based session bean. The class must be declared
11
* public according to the EJB specification.
12
*
13
* To generate the EJB related files to this EJB:
14
* - Add Standard EJB module to XDoclet project properties
15
* - Customize XDoclet configuration for your appserver
16
* - Run XDoclet
17
*
18
* Below are the xdoclet-related tags needed for this EJB.
19
*
20
* @ejb.bean name="HelloWorld"
21
* display-name="Name for HelloWorld"
22
* description="Description for HelloWorld"
23
* jndi-name="ejb/HelloWorld"
24
* type="Stateless"
25
* view-type="remote"
26
*/
27
public
class
HelloWorld
implements
SessionBean {
28
29
/**
The session context
*/
30
private
SessionContext context;
31
32
public
HelloWorld() {
33
super
();
34
//
TODO 自動生成構造函數存根
35
}
36
37
/**
38
* Set the associated session context. The container calls this method
39
* after the instance creation.
40
*
41
* The enterprise bean instance should store the reference to the context
42
* object in an instance variable.
43
*
44
* This method is called with no transaction context.
45
*
46
*
@throws
EJBException Thrown if method fails due to system-level error.
47
*/
48
public
void
setSessionContext(SessionContext newContext)
49
throws
EJBException {
50
context
=
newContext;
51
}
52
53
public
void
ejbRemove()
throws
EJBException, RemoteException {
54
//
TODO 自動生成方法存根
55
56
}
57
58
public
void
ejbActivate()
throws
EJBException, RemoteException {
59
//
TODO 自動生成方法存根
60
61
}
62
63
public
void
ejbPassivate()
throws
EJBException, RemoteException {
64
//
TODO 自動生成方法存根
65
66
}
67
68
/**
69
* An example business method
70
*
71
* @ejb.interface-method view-type = "remote"
72
*
73
*
@throws
EJBException Thrown if method fails due to system-level error.
74
*/
75
public
String hello()
throws
EJBException {
76
//
rename and start putting your business logic here
77
return
new
String(
"
HelloEJBWorld!
"
);
78
}
79
80
}
81
其實就是修改了其中的一個方法:
1
/**
2
* An example business method
3
*
4
* @ejb.interface-method view-type = "remote"
5
*
6
*
@throws
EJBException Thrown if method fails due to system-level error.
7
*/
8
public
String hello()
throws
EJBException {
9
//
rename and start putting your business logic here
10
return
new
String(
"
HelloEJBWorld!
"
);
11
}
注意:代碼中的解釋文字不要刪除,因為XDoclet需要。
配置屬性
添加weblogic.jar。我的路徑是:bea\weblogic90\server\lib\weblogic.jar
就下來寫EJBTest類:
1
package
com;
2
3
import
java.rmi.RemoteException;
4
import
java.util.Properties;
5
6
import
javax.ejb.CreateException;
7
import
javax.naming.Context;
8
import
javax.naming.InitialContext;
9
import
javax.naming.NamingException;
10
11
import
com.interfaces.HelloWorld;
12
import
com.interfaces.HelloWorldHome;
13
14
public
class
EJBTest {
15
16
/**
17
*
@param
args
18
*/
19
public
static
void
main(String[] args) {
20
//
TODO 自動生成方法存根
21
Properties properties
=
new
Properties();
22
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"
weblogic.jndi.WLInitialContextFactory
"
);
23
properties.setProperty(Context.PROVIDER_URL,
"
t3://localhost:7001
"
);
24
25
Context context;
26
try
{
27
context
=
new
InitialContext(properties);
28
HelloWorldHome hwh
=
(HelloWorldHome)context.lookup(
"
ejb/HelloWorld
"
);
29
HelloWorld hw
=
hwh.create();
30
String s
=
hw.hello();
31
System.out.println(s);
32
}
catch
(NamingException e) {
33
//
TODO 自動生成 catch 塊
34
e.printStackTrace();
35
}
catch
(RemoteException e) {
36
//
TODO 自動生成 catch 塊
37
e.printStackTrace();
38
}
catch
(CreateException e) {
39
//
TODO 自動生成 catch 塊
40
e.printStackTrace();
41
}
42
43
}
44
45
46
}
47
最后就是看結果了,先啟動weblogic,然后運行EJBTest程序。
發表于 2007-07-15 12:31
Masen
閱讀(202)
評論(0)
編輯
收藏
所屬分類:
EJB
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
代理EJB
圖解eclipse+myelcipse開發EJB
主站蜘蛛池模板:
临漳县
|
左贡县
|
张北县
|
武强县
|
平定县
|
海城市
|
赣榆县
|
东兴市
|
北海市
|
双江
|
建水县
|
金溪县
|
宁都县
|
博爱县
|
五大连池市
|
潞西市
|
玛沁县
|
威远县
|
资兴市
|
天长市
|
德清县
|
永清县
|
铜川市
|
吉隆县
|
井冈山市
|
金寨县
|
阜康市
|
吉首市
|
扬州市
|
花莲县
|
喀喇沁旗
|
麻江县
|
葫芦岛市
|
郧西县
|
三明市
|
南雄市
|
八宿县
|
府谷县
|
家居
|
紫阳县
|
天峻县
|