使用WebSphere Liberty Profile 8.5设置数据源 [英] Setting up a datasource with WebSphere Liberty Profile 8.5
本文介绍了使用WebSphere Liberty Profile 8.5设置数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Web应用程序通过以下方式从JNDI获取数据源:
My web app is getting a data source from JNDI with:
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)
ctx.lookup("java:comp/env/jdbc/db");
在应用程序的WEB-INF/web.xml
中,我有:
In the app's WEB-INF/web.xml
, I have:
<resource-ref>
<description>DataSource</description>
<res-ref-name>jdbc/db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
在应用程序的WEB-INF/ibm-web-bnd.xml
中,我有:
In the app's WEB-INF/ibm-web-bnd.xml
, I have:
<web-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host"/>
<resource-ref name="jdbc/db" binding-name="jdbc/db"/>
</web-bnd>
在WebSphere Liberty Profile的server.xml
中,我(保留相关部分):
In WebSphere Liberty Profile's server.xml
, I have (keeping on the relevant parts):
<server description="new server">
<featureManager>
<feature>jsp-2.2</feature>
<feature>jdbc-4.0</feature>
</featureManager>
<library id="oracle-lib">
<fileset dir="lib" includes="ojdbc5_g.jar"/>
</library>
<dataSource jndiName="jdbc/db" jdbcDriverRef="oracle-driver" type="javax.sql.DataSource">
<jdbcDriver libraryRef="oracle-lib" id="oracle-driver"/>
<connectionManager numConnectionsPerThreadLocal="10" id="ConnectionManager" minPoolSize="1"/>
<properties user="user" password="password"
url="jdbc:oracle:thin:@//db-server:1521/db"/>
</dataSource>
</server>
当应用尝试从JNDI获取数据源时,它将失败并显示以下错误:
When the app attempts to get the datasource from JNDI, it fails with the following error:
CWNEN0030E: The @Resource factory encountered a problem getting
the object instance jdbc/oracle binding object. The exception message was:
failed to resolve jdbc/oracle to javax.sql.DataSource:
javax.naming.NameNotFoundException:
Intermediate context does not exist: jdbc/oracle
我在这里想念什么?
推荐答案
WebSphere server.xml
<server>
<featureManager>
<feature>jndi-1.0</feature>
<feature>jdbc-4.1</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint"
host="localhost"
httpPort="9080"
httpsPort="9443" />
<library id="oracle-lib">
<fileset dir="lib" includes="ojdbc6_g.jar"/>
</library>
<dataSource jndiName="jdbc/oracle">
<jdbcDriver libraryRef="oracle-lib"/>
<properties.oracle user="orbeon" password="password"
url="jdbc:oracle:thin:@//localhost:1521/orbeon"/>
</dataSource>
<application name="orbeon" location="war/orbeon" type="war">
<classloader commonLibraryRef="oracle-lib"/>
</application>
</server>
WEB-INF/ibm-web-bnd.xml
<web-bnd version="1.0"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd">
<virtual-host name="default_host"/>
<resource-ref name="jdbc/oracle" binding-name="jdbc/oracle"/>
</web-bnd>
WEB-INF/web.xml
<resource-ref>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
资源注入(而不是web.xml + ibm-web-bnd.xml):
@Resource(lookup = "jdbc/oracle")
DataSource ds;
这篇关于使用WebSphere Liberty Profile 8.5设置数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文