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:
The 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:
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 :)
If you like this post, then consider subscribing to the full feed RSS.
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;Annotation "Remote" specifies that the class is remote interface of the bean.
import javax.ejb.Remote;
@Remote
public interface StatelessTestRemote {
public void doSomething();
}
The bean:
package com.test.stateless.beans;Annotation "Stateless" specifies that the class is stateless bean.
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 "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:
@StatelessThats it :)
@Remote ({StatelessTestRemote.class})
@RemoteBinding(jndiBinding =
"com/test/stateless/beans/StatelessTestBean/remote")
public class StatelessTestBean
implements StatelessTestRemote {
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 :)
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.
















