Very often you can read ” xml descriptors are dead with EJB 3 “. Well, it’s not exactly true. XML descriptors are not dead, they are optional (thank god). But there is still a very good and legitimate use for them when you want to configure an EJB. When you have an attribute in an EJB which value can change at deployment, you don’t want to change your code, recompile it, package it and redeploy the EJB. No, you just want to change an XML file (ejb-jar.xml), package it with your classes and deploy the EJB. So, how do we do that with EJB 3 ? Still using ENC ( environment namming context also sometimes called enterprise namming context ) but in a much easier way. ENC has been around since EJB 1.0 and can be seen as a local JNDI namespace specific to the container. You can bind many different items in the ENC (EJB references, JMS queues, topics, data source, user transaction…) but I will have a look at how to bind and use primitive values. Anything registered in the ENC can be looked up by name under the java:/com/env context ( comp means component ). Let’s take a simple stateless bean which defines a String str initialized with Hello World !!!. @Stateless public class ABean implements ABeanRemote { private String str = "Hello World !!!"; public String sayHello() { return ">>> " + str; } } Now, […]
Read More →