Developing stateless Session Bean in ejb3 under JBoss

Source: Internet
Author: User

1. Develop an ejb3 stateless sessionbean with remote and local interfaces.
If you cannot write it there, please give me more advice.
##############################
# Let's first introduce the star actors :#
##############################
Remote interface: remotehelloworld. Java
Local interface: localhelloworld. Java
Sessionbean: helloworldbean. Java
JNDI configuration: JNDI. properites
JSP: Hello. jsp

Package com. yourcompany. ejb3;
Public interface remotehelloworld {
Public String say (string name );
}

Package com. yourcompany. ejb3;
Public interface localhelloworld {
Public String say (string name );
}

Package com. yourcompany. ejb3;
Import javax. EJB. stateless;
Import javax. EJB. Remote;
Import javax. EJB. Local;
Import com. yourcompany. ejb3.remotehelloworld;
Import com. yourcompany. ejb3.localhelloworld;

@ Remote ({remotehelloworld. Class })
// The annotation indicates that remotehelloworld is the remote interface of this sessionbean.
@ Local ({remotehelloworld. Class })
// Note that localhelloworld is the local interface of this sessionbean

// @ Stateless annotation indicates that this is a stateless Session Bean
Public @ stateless class helloworldbean implements remotehelloworld, localhelloworld {
Public String say (string name ){
Return "this is a stateless ejb3 Session Bean, Author:" + name;
}
}
// The JNDI configuration tells your client to initialize the JNDI Naming Service.
JNDI. properties:
Java. Naming. Factory. Initial = org. jnp. Interfaces. namingcontextfactory
Java. Naming. Factory. url. pkgs = org. JBoss. Naming: org. jnp. Interfaces
Java. Naming. provider. url = localhost: 1099

Call in JSPCodeAs follows:
<%
Properties prop = new properties ();
Prop. Load (thread. currentthread (). getcontextclassloader (). getresourceasstream ("JNDI. properties "));
Initialcontext CTX = new initialcontext (PROP );
Remotehelloworld = (remotehelloworld) CTX. Lookup ("helloworldbean/remote ");
Remotehelloworld. Say ("christina007 [remote]");
Localhelloworld = (localhelloworld) CTX. Lookup ("helloworldbean/local ");
Localhelloworld. Say ("christina007 [local]");
%>

Running result:
This is a stateless ejb3 Session Bean, Author: christina007 [remote]

This is a stateless ejb3 Session Bean, Author: christina007 [local]

Summary steps:
1. Write the business logic interface of sessionbean.
2. Write sessionbean again. Remember to implement the business logic interface in sessionbean.

 

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.