JBoss EJB 3.0 STATELESS Beans

xiaoxiao2021-03-05  22

There are two examples below: one is a standard STATELESSBEAN, one is simplified STATELESSBEAN

Calculator.java // Calculator interface: plus, reduce

Package Org.jboss.tutorial.Stateless.Bean;

Public Interface Calculator

{

INT Add (int X, int y);

Int subtract (int X, int y);

}

CalculatorBean.java

Package Org.jboss.tutorial.Stateless.Bean;

Import javax.ejb.stateless;

@StateLess // Tag CalculatorBean is the implementation of local and remote interfaces for local and remote interfaces

Public Class CalculatorBean Implements CalculatorRemote, CalculatorLocal

{

Public Int Add (int X, int y)

{

Return X Y;

}

Public int subtract (int X, int y)

{

Return X - Y;

}

}

CalculatorLocal.java

Package Org.jboss.tutorial.Stateless.Bean;

Import javax.ejb.local;

@Local // Mark is a local interface, inheriting the calculator interface

Public Interface CalculatorLocal Extends Calculator

{

}

CalculatorRemote.java

Package Org.jboss.tutorial.Stateless.Bean;

Import javax.ejb.remote;

@Remote / / Mark as remote interface, inherited the calculator interface

Public Interface CalculatorRemote Extends Calculator

{

}

Client

Client.java

Package Org.jboss.tutorial.Stateless.Client;

Import org.jboss.tutorial.Stateless.Bean.calculator;

Import org.jboss.tutorial.Stateless.Bean.calculatorRemote;

Import javax.naming.initialcontext;

Public Class Client

{

Public static void main (string [] args) Throws Exception

{

InitialContext CTX = New InitialContext ();

/ / Find remote interface

Calculator Calculator = (Calculator) ctx.lookup (CalculatorRemote.class.getName ());

System.out.Println ("1 1 =" Calculator.Add (1, 1));

System.out.println ("1 - 1 =" Calculator.Subtract (1, 1));

}

}

************************************************************************************************* ************

STATELESSBEAN features can be implemented in just three programs.

Calculator.java

Package org.jboss.tutorial.stateless.bean; import javax.ejb.remote

@Remote / / Tag calculator as a remote interface directly

Public Interface Calculator

{

INT Add (int X, int y);

Int subtract (int X, int y);

}

CalculatorBean.java

Package Org.jboss.tutorial.Stateless.Bean;

Import javax.ejb.stateless;

@StateLess

Public Class CalculatorBean Implements Calculator // Really implemented a calculator interface

{

Public Int Add (int X, int y)

{

Return X Y;

}

Public int subtract (int X, int y)

{

Return X - Y;

}

}

Client:

Client.java

Package Org.jboss.tutorial.Stateless.Client;

Import org.jboss.tutorial.Stateless.Bean.calculator;

Import javax.naming.initialcontext;

Public Class Client

{

Public static void main (string [] args) Throws Exception

{

InitialContext CTX = New InitialContext ();

Calculator Calculator = (Calculator) ctx.lookup (Calculator.class.getName ());

// Just look up the interface marked as Remote.

System.out.Println ("1 1 =" Calculator.Add (1, 1));

System.out.println ("1 - 1 =" Calculator.Subtract (1, 1));

}

}

There is no log4j.properties in jboss-ejb-3.0_preview_5.zip, there is no such thing as a lack of appender

Log4j.properties

Log4j.Appender.r = org.apache.log4j.rollingfileappender

Log4j.Appender.r.file = record.log

Log4j.Appender.r.Layout = org.apache.log4j.patternlayout

Log4j.Appender.r.Layout.conversionPattern =% p% d {hh: mm: ss}% T% c {1} -% M% N

Log4j.Appender.r.maxbackupindex = 1

Log4j.Appender.r.maxfilesize = 100kb

Log4j.Appender.stdout.Layout = Org.apache.log4j.patternlayout

Log4j.Appender.stdout.Layout.conversionPattern =% 5P [% T] (% F:% L) -% M% N

Log4j.appender.stdout = org.apache.log4j.consoleAppender

Log4j.rootlogger = stdout, r

Run: Refer to Installing.html

Under Windows

Open the command prompt cmd to jboss_home / binrun.bat -c all

Use ANT

After Build, run.

discuss:

The simplified version is to see the Statefull source code in jboss-ejb-3.0_preview_5.zip, in EJB SPE 3.0, it seems to be deleted this interface, I think it simplifies a lot of interfaces, effective development J2EE Application

转载请注明原文地址:https://www.9cbs.com/read-37346.html

New Post(0)