【问题标题】:Multiple DataSource into Websphere Liberty ProfileWebsphere Liberty Profile 中的多个数据源
【发布时间】:2016-01-12 20:17:03
【问题描述】:

是否可以在 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"/>

埃里克

【问题讨论】:

    标签: jdbc datasource websphere-liberty


    【解决方案1】:

    是的,这是可能的。只需在 server.xml 中指定单独的 &lt;dataSource&gt; 元素。

    例如:

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

    请注意,两个数据源上都有一个jdbcDriverRef,它对应于&lt;jdbcDriver&gt; 元素的ID。这很方便,因此您不必在每次要声明 &lt;dataSource&gt; 时都指定另一个 JDBCDriver。

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

    或者,如果您愿意,您可以在数据源下嵌套&lt;jdbcDriver&gt; 元素。如果您从不在多个 &lt;dataSource&gt; 元素之间共享 &lt;jdbcDriver&gt;,这将是理想的。

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

    这里是 IBM 官方文档的链接:Configuring database connectivity in Liberty

    【讨论】:

    • 您好,感谢您的回答,但根据您的解释,我的配置仍然无法正常工作,我在主要问题中添加了更多信息。
    • pb 解决了,ibm-web-bnd.xml 不见了,很难找到整个链来配置这两个数据源...
    • 我需要做些什么来将我的帖子标记为已解决吗?
    • @EricReboisson ibm-web-bnd.xml 不是必需的,没有它也应该可以工作。您能否通过尝试查找/注入数据源的方式更新您的问题?以及您遇到的错误
    • 即使问题出在其他地方,我也接受了您的回答...我明天会看看是否已配置此应用程序。但它似乎是一个简单的 web 应用程序,具有标准结构,正如我在添加 ibm-web-bnd.xml 文件时的主要帖子中所说的那样,它就像一个魅力;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2013-02-03
    • 1970-01-01
    相关资源
    最近更新 更多