📄 4.mht
字号:
below=20
in code snippet.</B></P>
<P><IMG height=3D406=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessDAOImpl.pn=
g"=20
width=3D594 align=3Dleft border=3D0 name=3DGraphic11><BR =
clear=3Dleft><BR><BR></P>
<P><B>Now, all methods are implemented, and only deployment descriptors =
remain=20
to be done.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Deploy Bean =
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>In order to deploy our bean we have to declare a few tags in=20
StoreAccessStateBean class as shown below.</B></P>
<P><IMG height=3D296=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessStateBeanA=
llDescriptors.png"=20
width=3D518 align=3Dleft border=3D0 name=3DGraphic14><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add the tag shown below in StoreAccessStateBean at class level (at =
the=20
top).</B></P><PRE><FONT face=3DSans><FONT size=3D3><FONT =
color=3D#3f5fbf>@ejb.resource</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>ref</FONT> <FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>ref</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"jdbc/DefaultDS"</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>type=3D"javax.sql.Datasource"</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>auth=3D"Container"</FONT></FONT></FONT></PRE>
<P><B>This tag will generate deployment descriptors in ejb-jar.xml, as =
the bean=20
has to know which datasource you are going to connect, what is its type, =
etc.=20
This will generate these descriptors as shown below.</B></P>
<P><IMG height=3D320=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/ejb-jarResourceRef.pn=
g"=20
width=3D530 align=3Dleft border=3D0 name=3DGraphic15><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add this tag shown below in StoreAccessStateBean at class level =
(at=20
top).</B></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT face=3DSans><FONT =
size=3D3><FONT color=3D#3f5fbf>@jboss.resource</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>ref</FONT> <FONT =
color=3D#3f5fbf>res</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>ref</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"jdbc/DefaultDS" jndi<FONT =
color=3D#7f7f9f>-</FONT>name=3D"java:/DefaultDS<B>"</B></FONT></FONT></FO=
NT></PRE>
<P><B>This tag will generate deployment descriptors in jboss.xml, as the =
application server has to know with what jndi-name the datasource has =
been=20
registered with. This will generate these descriptors as shown =
below.</B></P>
<P><IMG height=3D158=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/jbossResourceRef.png"=
=20
width=3D418 align=3Dleft border=3D0 name=3DGraphic16><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add this tag shown below in StoreAccessStateBean at class level =
(at=20
top).</B></P><PRE><FONT size=3D3><FONT =
color=3D#3f5fbf>@jboss.container</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>configuration</FONT> <FONT =
color=3D#3f5fbf>name</FONT> <FONT color=3D#3f5fbf>=3D"Standard</FONT> =
<FONT color=3D#3f5fbf>Stateful</FONT> <FONT =
color=3D#3f5fbf>SessionBean"</FONT></FONT>
</PRE>
<P><B>This tag will generate deployment descriptors in jboss.xml, as the =
application server has to know which configuartion is to be read for =
Stateful=20
Bean from standardjboss.xml under =
/opt/jboss/jboss-3.2.1/server/all/conf/. This=20
will generate these descriptors in jboss.xml as shown =
below.</B></P><PRE><FONT size=3D3><session></FONT>
<FONT =
size=3D3><ejb-name>StoreAccessState</ejb-name></FONT>
<FONT =
size=3D3><jndi-name>StoreAccessStateBean</jndi-name></FONT>
<B><FONT size=3D3><configuration-name>Standard Stateful =
SessionBean</configuration-name></FONT></B>
<FONT size=3D3><resource-ref></FONT>
<FONT =
size=3D3><res-ref-name>jdbc/DefaultDS</res-ref-name></FONT>
<FONT =
size=3D3><jndi-name>java:/DefaultDS</jndi-name></FONT>
<FONT size=3D3></resource-ref> </FONT>
<FONT size=3D3></session></FONT></PRE>
<P><FONT color=3D#800000><I>Note : This configuration is for container =
in Jboss to=20
read for Stateful Session Bean. Jboss comes with timeout of 60 mins for =
stateful=20
session bean. Change the <B><max-bean-life> attribute to 120 secs =
(i:e2=20
mins) and restart your server </B>as shown below in code snippet from=20
/opt/jboss/jboss-3.2.1/servaer/all/conf/standardjboss.xml.</I></FONT></P>=
<PRE><FONT color=3D#800000><FONT =
size=3D3><container-configuration></FONT></FONT>
<FONT color=3D#800000> <FONT size=3D3><container-name>Standard =
Stateful SessionBean</container-name></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><call-logging>false</call-logging></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><invoker-proxy-binding-name>stateful-rmi-invoker</invok=
er-proxy-binding-name></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><container-interceptors></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3>----------------------------------------------------------------=
---</FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3>----------------------------------------------------------------=
------</FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3>----------------------------------------------------------------=
-----</FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><container-cache-conf></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><cache-policy>org.jboss.ejb.plugins.LRUStatefulContextCach=
ePolicy</cache-policy></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><cache-policy-conf></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><min-capacity>50</min-capacity></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><max-capacity>1000000</max-capacity></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><!--remover-period>1800</remover-period--></FONT></F=
ONT>
<FONT color=3D#800000> <FONT =
size=3D3><remover-period>120</remover-period></FONT></FONT>
<FONT color=3D#800000> <B><FONT =
size=3D3><max-bean-life>120</max-bean-life></FONT></B></FONT>=
<FONT color=3D#800000> <B><FONT size=3D3><!-- By default =
Jboss comes withh 60 mins time out for stateful bean,change =
it</FONT></B></FONT>
<FONT color=3D#800000> <B><FONT size=3D3>to 120 secs (2 =
mins) and restart the server to read this config.</FONT></B></FONT>
<FONT color=3D#800000> <B><FONT =
size=3D3>--></FONT></B></FONT>
<FONT color=3D#800000> <B><FONT =
size=3D3><!--max-bean-life>1800</max-bean-life--></FONT></B><=
/FONT>
<FONT color=3D#800000> <B><FONT size=3D3><!-- 1800 secs =3D =
30 mins --></FONT></B></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><overager-period>300</overager-period></FONT></FONT>=
<FONT color=3D#800000> <FONT =
size=3D3><max-bean-age>600</max-bean-age></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><resizer-period>400</resizer-period></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><max-cache-miss-period>60</max-cache-miss-period></F=
ONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><min-cache-miss-period>1</min-cache-miss-period></FO=
NT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3><cache-load-factor>0.75</cache-load-factor></FONT></=
FONT>
<FONT color=3D#800000> <FONT =
size=3D3></cache-policy-conf></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3></container-cache-conf></FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3>----------------------------------------------------------------=
------</FONT></FONT>
<FONT color=3D#800000> <FONT =
size=3D3>----------------------------------------------------------------=
-----</FONT></FONT></PRE>
<P>Now, everything is complete, and it's time to deploy the bean.</P>
<P><B>First, regenerate your EJB classes as shown in the steps above for =
the=20
final time.</B></P>
<P><FONT color=3D#800000><I>Note : We have regenerated the classes again =
and again=20
in order to explain every step and its result. Once you are familiar =
with these=20
steps you will only need to generate your classes a few times as you go. =
Either=20
way, it doesn't affect your implementation, so you can (re)generate your =
classes=20
however you prefer to work.</I></FONT></P>
<P><B>Go to Lomboz J2EE View > expand node MyStore > expand =
MyStoreMgr=20
> select 'Jboss 3.2.1 ALL' .</B></P>
<P><B>Right click > select 'Debug Sever' on the pop up menu.</B></P>
<P><B>Go to MyStoreMgr node in LombozJ2EE view > right click > =
select=20
Deploy on the pop up menu</B>.</P>
<P><FONT color=3D#800000><I>Note : These steps are covered in the =
previous=20
chapter.</I></FONT></P>
<P>And now wait for your deployment result.</P>
<P>If everything goes fine, you will have this message under your =
console as=20
shown below.</P>
<P><IMG height=3D294=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/LombozJ2EEBeanDeploye=
d.png"=20
width=3D710 align=3Dleft border=3D0 name=3DGraphic17><BR =
clear=3Dleft><BR><BR></P>
<P>So, now your bean is deployed successfully, let's create a test =
client, which=20
will invoke the loginUser method on StoreAccessStateBean.</P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><BR></H3>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create your Test =
Client=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>Go to Project MyStore node > select src node > right =
click.</B></P>
<P><B>Select New on pop up menu > select Lomboz EJB Test Client =
Wizard</B>=20
<B>as shown below</B>. </P>
<P><IMG height=3D232=20
src=3D"http://www.tusc.com.au/tutorial/images/chap3/CreateEJBTestClient.p=
ng"=20
width=3D507 align=3Dleft border=3D0 name=3DGraphic32><BR =
clear=3Dleft><BR><BR></P>
<P><B>Select package name au.com.tusc.client, with name =
SessionStateClient and=20
select Ejb Home as au.com.tusc.sessionState.StoreAccessStateHome and Ejb =
Interface as au.com.tusc.sessionState.StoreAccessState</B> <B>as shown=20
below</B>.</P>
<P><IMG height=3D466=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/CreateEJBTestClientPa=
ckageName.png"=20
width=3D548 align=3Dleft border=3D0 name=3DGraphic18><BR =
clear=3Dleft><BR><BR></P>
<P><B>This will generate the necessary helper methods for you in your=20
SessionStateClient class and you simply have to invoke the loginUser =
method on=20
bean. </B></P>
<P><B>So add the lines of code shown below in the testBean method. =
</B></P><PRE><FONT size=3D3><FONT color=3D#7f0055>public</FONT> <FONT =
color=3D#7f0055>void</FONT> <FONT color=3D#000000>testBean()</FONT> =
<FONT color=3D#000000>{</FONT></FONT>
<FONT color=3D#000000> <FONT size=3D3>String</FONT> userID =3D =
<B><FONT color=3D#7f0055>null</FONT></B>;</FONT>
<FONT color=3D#7f0055> <B><FONT size=3D3>try</FONT></B> <FONT =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -