EJB 3.1 available on JBoss 6

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 
Java EE 1.6 has been officially last December. Now we are pleased to learn that the release 6 M2 of JBoss application server, finally includes also some EJB 3.1 stuff.
In a previous article we have added a preview to the EJB 3.1 technology. Now you can play with some cool features which are included in the release 6.0.0 M2 of the application server.

Feature #1 No interface view

EJB Interfaces are no longer needed. You need just to add a @Stateless or @Stateful annotation and that's all. This avoid the burden of replicating some/all methods from the Bean class to the interface view.
Here's an example:

package ejb;
 
import javax.ejb.Stateless;
 
@Stateless

public class NoInterfaceBean
{
   public String sayHello(String name)
   {
      return "Hello " + name;
   }
 
}

When you deploy this EJB, the container recognizes that is a no-interface bean and creates a Local interface automatically for you.

 
This of course means that if you need to expose your bean with remote interface, you need to provide another Bean which acts as Session Facade to your no-interface EJB. 
As a consequence of this, the use case for no-interface EJB are mainly for application which are fronted by the Web tier, which in turn communicates with the EJB (local) tier.  

Feature #2 EJB can now packed into Web application Archives (.war)


The most interesting news of this new release is the ability to deploy your EJB along with your Web application. This means that :

 

  • It will be easier to pack and deploy your application archives because you don't need to create an Enterprise Application Archive (.ear) for applications made up just of Servlet and EJBs
  • Also, you don't need to worry about separating common classes in a .jar file which will be deployed in your Enterprise Archive (And referenced as a Java Module in your application.xml)

The following Servlet has our no-interface Bean injected and deployed in the same Web Archive: 
public class ServletController extends HttpServlet {
    @EJB(mappedName="NoInterfaceBean/no-interface")
    NoInterfaceBean ejb;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
       

        try {
            out.println(ejb.sayHello("Frank"));         
            out.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}    
Notice how little coding we have saved from earlier EJB specifications! ( No interfaces needed, no Service Locator class, no need to create separate archives for application...)


You can pack your EJBs in two ways:
1) Simply add the EJBs in the classes folder, like a normal Bean/Servlet:  

WebApp.war
¦   index.jsp
¦
+---WEB-INF
    ¦   web.xml
    ¦
    +---classes
        +---ejb
        ¦       NoInterfaceBean.class
        ¦
        +---servlet
                ServletController.class


2) Pack your EJB classes in an archive and include it in the WEB-INF/lib folder:                                             

WebApp.war
¦   index.jsp
¦
+---WEB-INF
    ¦   web.xml
    ¦
    +---classes
    ¦   ¦
    ¦   +---servlet
    ¦       ServletController.class    
    +---lib
        ¦ 
        +---ejb-classes.jar  

That's all for now. As soon as the EJB 3.1 specification will be full implemented, we will add new articles so stay tuned!

Related articles available on mastertheboss.com

EJB 3.0 tutorial : Session Beans

Enterprise JavaBeans (EJB) technology is a J2EE technology for de

JBoss MDB 3.0

Message-driven beans (MDBs) are stateless, server-side, transacti

JBoss EJB 3 BMT

In a Bean Managed Transaction, the code in the session or message

How do you keep your EJB callbacks separated from biz. methods?

JBoss daily recipe

How to set EJB timeout period ?

JBoss recipe of the day

How to add a Selector with MDB 3.0 ?

Message selectors allow an MDB to be more selective about the mes

Follow us on Twitter