Java – find JDBC datasource in WebSphere 8.5

I want to use JDBC connection in my webapp, which is configured in WebSphere (like here: how to use JDBC in JavaEE?)

I have used this datasource through JPA before, but our customers want to have native SQL... Don't ask

I found many examples and tutorials (for example http://www.wickcentral.com/java/dl/ds_resreferencesetts_Websphere.pdf , WebSphere JNDI lookup failures), but there is nothing to want

Datasource in WebSphere has JNDI name "JDBC / MYDS"

I'm on my web A resource ref is added to the XML:

<resource-ref>
    <res-ref-name>jdbc/myDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>

I try to get datasource in my Dao:

ds = (DataSource) new InitialContext()
                .lookup("java:comp/env/jdbc/myDS");

But what I got was a

com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding Could not be found for the following resource references [jdbc/myDS],defined for the MyAPP component.

I tried a lot Did anyone see this mistake?

Solution

During installation, did you match the data source defined by web app with the data source defined by WebSphere? WebSphere usually requires you to bind resources when resources are detected during installation (if I remember correctly, it is in the step called "mapping reference resources to resources")

Another common problem is the WebSphere data source in a different context (cell / node / server) from your application, so it cannot be found at run time

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>