After I published my last blog Using EJB 3.0: Lean and Thin EJB, I got few emails from developers asking me to send them the code for HelloWorld EJB that use annotations. Couple of them asked whether ejb-jar.xml would no longer be used? Yes, EJB 3.0 is trying to remove the requirement of packaging ejb-jar.xml for those who hate XML by using defaults and exploiting use of metadata annotation. However you will be able to override annotation by packaging XML deployment descriptors.
Here is the content of my XML deployment descriptor that I used in earlier HelloWorld EJB.
<ejb-jar>
<enterprise-beans>
<session>
<description>Session Bean ( Stateless )</description>
<display-name>HelloWorld</display-name>
<ejb-name>HelloWorld</ejb-name>
<remote>oracle.ejb30.HelloWorld</remote>
<ejb-class>oracle.ejb30.HelloWorldBean</ejb-class>
<session-type>Stateless</session-type>
</session>
</enterprise-beans>
</ejb-jar>
The only change in this deployment descriptor with respect to EJB 2.1 is that I do not have <home> defined for the EJB.
I modified my HelloWorld EJB as follows to get rid of the ejb-jar.xml
package oracle.ejb30;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorld
{
public String sayHello(String nom)
{
final String result = "Hello " + nom + " from your EJB 3.0 with annotation";
System.out.println(result);
return result;
}
}
I compiled and packaged the bean class and remote interface and deployed to my container and the client application was ready to go. Isn't this neat?
Annotations will really simplify developers' life but you have to be careful because overuse of annotations can make your application less portable.
6:55:27 AM
|