You could use the resource-ref entry:
<enterprise-beans> <session> <ejb-name>ABC</ejb-name> ... <resource-ref> <res-ref-name>myDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> </resource-ref> ... </session> ... ...
jboss.xml (for other servers, they would have their own deployment descriptor):
<enterprise-beans> <session> <ejb-name>ABC</ejb-name> ... <resource-ref> <res-ref-name>myDataSource</res-ref-name> <jndi-name>java:DefaultDS</jndi-name> </resource-ref> ... </session> ...
@Resource (name="myDataSource") private DataSource myDS;
Thanks for answer, but I'm not sure if it is the right way to go for us.
As I understand we should create deployment descriptors for all the beans that use our data sources. The problem is that we have thousands of beans using the same data sources and the @Resource injection is done in a super class all our beans inherit from.
One of the goals with upgrading to EJB3 was to eliminate needs for individual, bean specific deployment descriptors.
Is it possible to create these mappings globally, once for the entire application?
A really old post but hurts me now.
I have a JEE 6 application which happily runs on Glassfish 3.1.x and injection on EJB just ave "jdbc/some-name".
Do I really have to wrote the hated xml configuration or this was addressed in newer JB versions?
What Jaikiran has mentioned is the only way out. MappedName is not portable according to Commons Annotations specification (JSR 250) Section 2.3 javax.annotation.Resource.
Below is the excerpt
"The mappedName element is a product specific name that this resource should be mapped to. The name of this resource, as defined by the name element or defaulted, is a name that is local to the application using the resource. Many application servers provide a way to map these local names to names of resources known to the application server. The mapped name could be of any form. Application servers are not required to support any particular form or type of mapped name, nor the ability to use mapped names. The mapped name is product-dependent and often installation-dependent. No use of mapped name is portable."
Thanks for the lesson but doesn't resolve my problem.
Also AFAIK name is not the same as mappedName.
Bottom line: Even if JEE promises deploy anywhere without resource portable names we have to use, again, configuration files.