-
1. Re: How to inject data source in AS independent way?
jaikiran May 11, 2009 9:28 AM (in response to japase)You could use the resource-ref entry:
ejb-jar.xml:<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> ...
EJB code:@Resource (name="myDataSource") private DataSource myDS;
-
2. Re: How to inject data source in AS independent way?
japase May 12, 2009 3:07 AM (in response to japase)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? -
3. Re: How to inject data source in AS independent way?
ssamayoagt Feb 3, 2014 5:26 PM (in response to japase)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?
Regards.
-
4. Re: How to inject data source in AS independent way?
abhijithtn Feb 4, 2014 7:48 AM (in response to japase)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."
-
5. Re: How to inject data source in AS independent way?
ssamayoagt Feb 4, 2014 8:15 AM (in response to abhijithtn)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.
Regards.