Adam Bien's Weblog

Simplest Possible, Annotation-Less EJB 3.1

The Bean is just a POJO - without any dependencies to libraries etc: 

public class MessageFacade {
public String hello(){
return "Working without annotations";

You will need to specify everything in XML:

<ejb-jar xmlns = ""
         version = "3.1"
         xmlns:xsi = ""
         xsi:schemaLocation = "">

Now you can use already the no-interface view Bean and inject it into a servlet (JSF backing beans, interceptors, other beans):

public class FrontController extends HttpServlet {
MessageFacade facade;

With XML (ejb-jar.xml) you could develop the whole application without even having the EJB 3.X API in your classpath...

This sample was deployed as a WAR. The ejb-jar.xml has to be placed into WEB-INF.

The project (AnnotationLessEJB31) was pushed into: The code was tested with Netbeans 6.7 and Glassfish v3 Prelude. Netbeans 6.7, however,  does not support EJB 3.1 directly. You will have to copy the ejb-jar.xml from src/java/conf into build/web/WEB-INF/ manually or change the ANT-script.

[Its one of the introductory samples (Chapter 1) from the "Real World Java EE Patterns" book]

NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming


A book about rethinking Java EE Patterns


Thank you, It was really helpful.

Posted by Mehdi on July 20, 2011 at 12:10 PM CEST #

Hi Adam,

remember that it's better to add the attribute metadata-complete="false" to the element <ejb-jar>.

Just with this it is possible to mix XML based and annotation based declaration of a bean.

It's a pity that it's still not possible to define a MDB as an endpoint for a (inbound) resource adapter without the neccessary XML deployment descriptor :-(

Looking forward to Java EE 7/8 to completely avoid XML's at all (even beans.xml as well as ra.xml)...

Regards and enjoy SF+JavaOne!

Posted by Robert on October 01, 2011 at 05:11 AM CEST #

If i want to use custom JNDI name that how can i do this. i am using jboss 7.1 and EJB3.1

Posted by Rajiv on July 30, 2015 at 09:47 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments