Home | About the author | Resume | << JBoss Clustering - HASingleton service | Drools - working with Stateless session >>
SMS Bundle - Mobile Marketing Solutions
SMS Bundle is an Australian-based service for sending marketing SMS and MMS

Stateless beans and annotations

Create stateless bean using annotations

Since EJB 3.0, it is possible to use JDK 5.0 metadata annotations to create EJB 3.0 Java beans. This makes the development very easy. The only drawback here as I see it, that in case when you want to change/add/remove annotation you actually have to recompile the class.

The example below shows how to create a stateless enterprise Java bean using annotations. The bean implements remote interface.

The interface:
package com.test.stateless.interfaces;

import javax.ejb.Remote;

@Remote
public interface StatelessTestRemote {

public void doSomething();
}
Annotation "Remote" specifies that the class is remote interface of the bean.

The bean:
package com.test.stateless.beans;

import javax.ejb.Stateless;
import org.jboss.annotation.ejb.RemoteBinding;
import com.test.stateless.interfaces.StatelessTestRemote;

@Stateless
@RemoteBinding(jndiBinding =
"com/test/stateless/beans/StatelessTestBean/remote")

public class StatelessTestBean
implements StatelessTestRemote {

public void doSomething() {

}
}
Annotation "Stateless" specifies that the class is stateless bean.
Annotation "RemoteBinding" specifies JNDI name for the interface.

Keep in mind, that you can use @Remote in implementation bean itself, and it doesnt have to be inside the interface class. For example:
@Stateless
@Remote ({StatelessTestRemote.class})
@RemoteBinding(jndiBinding =
"com/test/stateless/beans/StatelessTestBean/remote")

public class StatelessTestBean
implements StatelessTestRemote {
Thats it :)

Update:
As Laird Nelson has pointed out in his response to this post, it is possible to override annotations in the XML descriptor. I looked into it, and yes indeed - EJB 3.0 allows to override the behavior of annotations in the source code. Although there are some limitations which annotations can be overridden. You can refer to article JBoss EJB 3.0 partial deployment descriptors to find more detailed explanation about it :)
Categories : beans, stateless beans
Technorati Tags : , , ,
Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!

Related Posts
Deployment of mbean separately to its interface
JBoss Clustering - HASingleton service
JBoss Clustering - How many nodes in the cluster?
JBoss Clustering - Shared state across cluster partition
JBoss Clustering Architecture - Distributed Replicant Manager




If you like this post, then consider subscribing to the full feed RSS.



Re: Stateless beans and annotations

You can also override annotations in the XML deployment descriptor.

Re: Stateless beans and annotations

Thanks Laird!
I will look into it :D

Add a comment    Send a TrackBack