Search code examples
resourceswebsphere

Websphere application resource


How is possible to "ereditate" application resources in web module? My EAR structure is something like (standard structure I think):

EAR
+-----Web Module
+-----EJB Module
+-----Utility JAR Module

Now, what I want to achieve is to define resources at application level and use them in every module. I've tried with this configuration with no success:

application.xml

...
<resource-ref>  
   <description>my file properties</description>
    <res-ref-name>url/myUrl</res-ref-name>
    <res-type>java.net.URL</res-type>
    <res-sharing-scope>Shareable</res-sharing-scope> 
</resource-ref>

ibm-application-bnd.xml

...
<resource-ref name="url/realJndiName" binding-name="url/myUrl" />

web module class

@WebService
public class MyClass {
     @Resource(name="url/myUrl")
     URL myUrl;

     ....
}

But the injection fails. How should this be done? Of course if I move the resource definition in app.xml (with its bindings) everything works, but then I should move the resource even on ejb-jar.xml for EACH ejb which uses it...

Any hint?

Thanks


Solution

  • ibm-application-bnd.xml is intended for java:app and java:global references defined in application.xml, not references defined anywhere in the application. That approach works fine if you want to declare a single reference and have all components (servlets, EJBs, etc.) share the same reference. If you want each component to have a unique reference, then you need to declare the references separately and use per-component bindings in ibm-ejb-jar-bnd.xml, ibm-web-bnd.xml, etc.