4
votes

I have a JDBC datasource defined in WebSphere named 'jdbc/dataSource1'.
In my application based on Spring i want to obtain the datasource using jndi lookup, but by another name, like 'jdbc/dataSource2'.
To achieve this i created ibm-web-bnd.xml file, in which i defined the linkage as follows:

<resource-ref binding-name="jdbc/dataSource2" name="jdbc/dataSource1"/>

Also i defined the datasource in the web.xml file as follows:

<resource-ref>
    <description>some awesome datasource</description>
    <res-ref-name>jdbc/dataSource2</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

The solution works only while deploying using IBM Web Console. When i try to deploy it using custom jython script using wsadmin tool, i get the following error:

ADMA0007E: A Validation error occurred in task Mapping resource references to re
sources. The Java Naming and Directory Interface (JNDI) name is not specified f
or reference binding jdbc/dataSource2 in module <application_name>.war"

In wsadmin script i use AdminApp.install(path_to_ear, options), where options variable contain only options regarding virtual hosts mapping.

So the question is what should i do, so the WebSphere will get the datasource mapping options from ibm-web-bnd.xml file?

2

2 Answers

3
votes

You'll need to add MapResEnvRefToRes option to AdminApp.install call to map resource reference to resource. Check this link for more:

http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rxml_taskoptions.html#rxml_taskoptions__cmd56

The quickest way to get it done is to enable "command assistance logging" and proceed with installation via AdminConsole. In the command assistance log you'll find the exact AdminApp.install syntax for your deployment and mapping of resource references to actual resources.

Ad mode (I'm contributing to OSS project mentioned below)

If you consider more sophisticated automation project (not just one application install), then you may find WDR library useful. With WDR you can export all your application settings into a manifest file, which includes MapResEnvRefToRes settings. Then you can deploy the application based on that manifest.

3
votes

Try to call AppAdmin.install(path_to_ear) without options. Then options are read from the bnd file and there is no validation error. And ensure that ibm-web-bnd.xml file is in the ear file.

UPDATE

Ok I've noticed your error. In your binding file it should be the other way around:

<resource-ref name="jdbc/MyRef" binding-name="jdbc/JNDI" />

so in your case name is datasource2 and binding is jndiname - so datasource1:

<resource-ref binding-name="jdbc/dataSource1" name="jdbc/dataSource2"/>