⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
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>&lt;session&gt;</FONT>
  <FONT =
size=3D3>&lt;ejb-name&gt;StoreAccessState&lt;/ejb-name&gt;</FONT>
  <FONT =
size=3D3>&lt;jndi-name&gt;StoreAccessStateBean&lt;/jndi-name&gt;</FONT>
  <B><FONT size=3D3>&lt;configuration-name&gt;Standard Stateful =
SessionBean&lt;/configuration-name&gt;</FONT></B>
  <FONT size=3D3>&lt;resource-ref&gt;</FONT>
      <FONT =
size=3D3>&lt;res-ref-name&gt;jdbc/DefaultDS&lt;/res-ref-name&gt;</FONT>
      <FONT =
size=3D3>&lt;jndi-name&gt;java:/DefaultDS&lt;/jndi-name&gt;</FONT>
  <FONT size=3D3>&lt;/resource-ref&gt;  </FONT>
<FONT size=3D3>&lt;/session&gt;</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>&lt;max-bean-life&gt; 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>&lt;container-configuration&gt;</FONT></FONT>
<FONT color=3D#800000>  <FONT size=3D3>&lt;container-name&gt;Standard =
Stateful SessionBean&lt;/container-name&gt;</FONT></FONT>
<FONT color=3D#800000>    <FONT =
size=3D3>&lt;call-logging&gt;false&lt;/call-logging&gt;</FONT></FONT>
<FONT color=3D#800000>    <FONT =
size=3D3>&lt;invoker-proxy-binding-name&gt;stateful-rmi-invoker&lt;/invok=
er-proxy-binding-name&gt;</FONT></FONT>
<FONT color=3D#800000>    <FONT =
size=3D3>&lt;container-interceptors&gt;</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>&lt;container-cache-conf&gt;</FONT></FONT>
<FONT color=3D#800000>     <FONT =
size=3D3>&lt;cache-policy&gt;org.jboss.ejb.plugins.LRUStatefulContextCach=
ePolicy&lt;/cache-policy&gt;</FONT></FONT>
<FONT color=3D#800000>       <FONT =
size=3D3>&lt;cache-policy-conf&gt;</FONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;min-capacity&gt;50&lt;/min-capacity&gt;</FONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;max-capacity&gt;1000000&lt;/max-capacity&gt;</FONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;!--remover-period&gt;1800&lt;/remover-period--&gt;</FONT></F=
ONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;remover-period&gt;120&lt;/remover-period&gt;</FONT></FONT>

<FONT color=3D#800000>           <B><FONT =
size=3D3>&lt;max-bean-life&gt;120&lt;/max-bean-life&gt;</FONT></B></FONT>=

<FONT color=3D#800000>           <B><FONT size=3D3>&lt;!-- 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>--&gt;</FONT></B></FONT>
<FONT color=3D#800000>           <B><FONT =
size=3D3>&lt;!--max-bean-life&gt;1800&lt;/max-bean-life--&gt;</FONT></B><=
/FONT>
<FONT color=3D#800000>           <B><FONT size=3D3>&lt;!-- 1800 secs =3D =
30 mins --&gt;</FONT></B></FONT>

<FONT color=3D#800000>           <FONT =
size=3D3>&lt;overager-period&gt;300&lt;/overager-period&gt;</FONT></FONT>=

<FONT color=3D#800000>           <FONT =
size=3D3>&lt;max-bean-age&gt;600&lt;/max-bean-age&gt;</FONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;resizer-period&gt;400&lt;/resizer-period&gt;</FONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;max-cache-miss-period&gt;60&lt;/max-cache-miss-period&gt;</F=
ONT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;min-cache-miss-period&gt;1&lt;/min-cache-miss-period&gt;</FO=
NT></FONT>
<FONT color=3D#800000>           <FONT =
size=3D3>&lt;cache-load-factor&gt;0.75&lt;/cache-load-factor&gt;</FONT></=
FONT>
<FONT color=3D#800000>        <FONT =
size=3D3>&lt;/cache-policy-conf&gt;</FONT></FONT>
<FONT color=3D#800000>      <FONT =
size=3D3>&lt;/container-cache-conf&gt;</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 &gt; expand node MyStore &gt; expand =
MyStoreMgr=20
&gt; select 'Jboss 3.2.1 ALL' .</B></P>
<P><B>Right click &gt; select 'Debug Sever' on the pop up menu.</B></P>
<P><B>Go to MyStoreMgr node in LombozJ2EE view &gt; right click &gt; =
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 &gt; select src node &gt; right =
click.</B></P>
<P><B>Select New on pop up menu &gt; 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 + -