将多个数据源导入Websphere Liberty Profile

埃里克·雷博森(Eric Reboisson)

是否可以在Websphere Liberty Profile server.xml中声明多个数据源?有什么例子吗?

我尝试这样做,但只能看到一个。当查找第二个时,我收到一条错误消息,提示找不到jndi名称。

我的server.xml

    <?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-7.0</feature>
        <feature>jndi-1.0</feature>
        <feature>jdbc-4.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <!-- Configuration for DSPB  -->

    <jndiEntry jndiName="dspb/configuration/files" value="classpath:properties/dspb.properties,classpath:properties/dspb_db_connector.properties" />

    <dataSource id="ds1" jndiName="DB_DSPB_ACTIVITI" connectionManagerRef="connectionManager1" jdbcDriverRef="MyJDBCDriver">

        <properties.oracle driverType="thin" databaseName="xe"
                     serverName="localhost" portNumber="1521"
                     user="dspb_activiti" password="dspb_activiti"/>
    </dataSource>

    <dataSource id="ds2" jndiName="DB_DSPB" connectionManagerRef="connectionManager2" jdbcDriverRef="MyJDBCDriver">

        <properties.oracle driverType="thin" databaseName="xe"
                     serverName="localhost" portNumber="1521"
                     user="dspb" password="dspb"/>
    </dataSource>   

    <connectionManager id="connectionManager1" maxPoolSize="20" minPoolSize="5" 
                       connectionTimeout="10s" agedTimeout="30m"/>

    <connectionManager id="connectionManager2" maxPoolSize="20" minPoolSize="5" 
                       connectionTimeout="10s" agedTimeout="30m"/>

    <jdbcDriver id="MyJDBCDriver">
        <library>
            <fileset dir="C:/oraclexe/app/oracle/product/11.2.0/server/jdbc/lib/" includes="ojdbc6.jar"/>
        </library>
    </jdbcDriver>

</server>

还有web.xml中的定义

  <resource-ref>
    <res-ref-name>DB_DSPB</res-ref-name>
    <res-type>javax.sql.ConnectionPoolDataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

<resource-ref>
    <res-ref-name>DB_DSPB_ACTIVITI</res-ref-name>
    <res-type>javax.sql.ConnectionPoolDataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

<resource-ref>
    <res-ref-name>dspb/configuration/files</res-ref-name>
    <res-auth>Container</res-auth>
</resource-ref>

而且我只能在jconsole视图中看到DSPB:http ://i.stack.imgur.com/euN8e.jpg

怎么了 ?

因此,ibm-web-bnd.xml丢失了,这很狡猾……

<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">

<resource-ref name="DB_DSPB" binding-name="DB_DSPB"/>
<resource-ref name="DB_DSPB_ACTIVITI" binding-name="DB_DSPB_ACTIVITI"/>

埃里克

安迪·吉伯特(Andy Guibert)

是的,这是可能的。只需<dataSource>在server.xml中指定单独的元素。

例如:

<dataSource id="ds1" jndiName="jdbc/ds1" jdbcDriverRef="MyJDBCDriver">
    <properties ... />
</dataSource>

<dataSource id="ds2" jndiName="jdbc/ds2" jdbcDriverRef="MyJDBCDriver">
    <properties ... />
</dataSource>

请注意,两个数据源都jdbcDriverRef在其上具有一个,它对应于<jdbcDriver>元素的ID 这很方便,因此您不必每次都要声明另一个JDBCDriver <dataSource>

<jdbcDriver id="MyJDBCDriver">
    <library>
        <fileset dir="${server.config.dir}/jdbcDrivers" includes="driver.jar"/>
    </library>
</jdbcDriver>

或者,可以<jdbcDriver>选择将元素嵌套在数据源下。如果您不希望<jdbcDriver>在多个<dataSource>元素之间共享A 那么这将是理想的选择

<dataSource id="ds1" jndiName="jdbc/ds1">
    <properties ... />
    <jdbcDriver>
        <library>
            <fileset dir="${server.config.dir}/jdbcDrivers" includes="someJDBCDriver.jar"/>
        </library>
    </jdbcDriver>
</dataSource>

这是指向IBM官方文档的链接:在Liberty中配置数据库连接

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法配置Websphere Liberty Profile 8.5.5.7

将 Fixpack 应用到 WebSphere Liberty Profile

如何为WebSphere Liberty Profile生成LTPA令牌

在WebSphere Liberty Profile 8.5.x中禁用压缩

如何通过JMX在WebSphere Liberty中创建数据源

Websphere Liberty 18.0.0.3 MySQL数据源对象未注入

WebSphere Liberty概要文件数据源和CDI

Liberty Profile 8.5.5.5上的CodeSource

在Eclipse之外配置IBM Websphere Liberty Profile Server启动和停止超时值

如何在Eclipse中增加WebSphere Application Server V8.5 Liberty Profile的堆大小?

我应该将我的Websphere Liberty Profile项目添加到SCM吗?

在Tomcat和Websphere Liberty Profile中执行时,Jersey Client提供两组结果

对于WebSphere Liberty Profile,bootstrap.properties文件中的反斜杠字符

Teradata JNDI 数据源 WAS Liberty

WAS Liberty Profile JSF2 Portlet

使用IBM WebSphere Application Server Liberty概要文件配置Mysql数据源

有什么方法可以像传统那样在Websphere Liberty中测试数据源?

无法从命令行启动Liberty Profile:无法创建任务或键入antlib:com.ibm.websphere.wlp.ant:server

Websphere Liberty Profile:[警告] SRVE0190E:在 EAR 文件中包含的库中找不到文件

如何在WebSphere Liberty Profile中使用DB2配置log4j2 JDBCAppender

WebSphere Liberty 的 EJB 绑定

Websphere Scheduler与Liberty Scheduler

如果可以在Liberty Profile(非ND)中访问AdminConfig

如何使依赖项注入在Liberty Profile中工作

Worklight Studio + WAS Liberty Profile 8.5.5 =>在WAS ND 8.5.5上部署

IBM WebSphere Liberty数据源可以从server.xml拆分为一个包含文件吗?

Cargo是否支持WebSphere Liberty?

将LDAP配置从Websphere迁移到Liberty

如何使用Websphere Liberty显示HTML文件?