Jboss EJB 3.0--stateless Beans

Source: Internet
Author: User
Tags interface return string zip client jboss log4j

Jboss EJB 3.0



Stateless Beans







Calculator.java//Calculator interface: Add, subtract



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//Mark Calculatorbean as stateless bean, implementation 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//marked as local interface, inherited calculator interface



Public interface Calculatorlocal extends Calculator



{



}







Calculatorremote.java



Package Org.jboss.tutorial.stateless.bean;







Import Javax.ejb.Remote;







@Remote//marked as remote interface, inherited 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 a 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));



}



}































Simplified version ********************************







Statelessbean function can be achieved with only three programs.



Calculator.java



Package Org.jboss.tutorial.stateless.bean;







Import Javax.ejb.Remote;







@Remote//Directly mark calculator as a remote interface



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



The public class Calculatorbean implements Calculator//here implements the 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 for an interface that's marked as remote.



System.out.println ("1 + 1 =" + Calculator.add (1, 1));



System.out.println ("1-1 =" + calculator.subtract (1, 1));



}



}











Here attached log4j.properties inside Jboss-ejb-3.0_preview_5.zip No this is always showing 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















Running: Reference installing.html



Under Windows



Open command Prompt cmd, to Jboss_home/bin



Run.bat–c All



With Ant



Just build and run.











Discuss:



The simplified version is to see the jboss-ejb-3.0_preview_5.zip inside the statefull source and rewrite, in the EJB SPE 3.0 said like to delete the home interface, I think the simplification of many interfaces more aspects, effective development of Java EE Application




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.