Jdbc 将多个数据源导入Websphere Liberty概要文件

Jdbc 将多个数据源导入Websphere Liberty概要文件,jdbc,datasource,websphere-liberty,Jdbc,Datasource,Websphere Liberty,是否可以将多个数据源声明到Websphere Liberty Profile server.xml中?有什么例子吗 我试着去做,但我只能看到一个。当第二个被查找时,我有一条错误消息说找不到jndi名称 Myserver.xml: <?xml version="1.0" encoding="UTF-8"?> <server description="new server"> <!-- Enable features --> <fe

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

我试着去做,但我只能看到一个。当第二个被查找时,我有一条错误消息说找不到jndi名称

Myserver.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>
  <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>

webProfile-7.0
jndi-1.0
jdbc-4.0

怎么了

因此,IBMWebBND.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"/>


Eric

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

例如:

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

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

或者,如果选择,可以将
元素嵌套在数据源下。如果您从不在多个
元素之间共享
,这将是理想的选择

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


这里有一个指向IBM官方文档的链接:

您好,谢谢您的回答,但根据您的解释,我的配置仍然不起作用,我在主要问题中添加了更多信息。Pb已解决,IBM-web-bnd.xml丢失,很难找到完整的链来配置这两个数据源……我是否需要做些什么来将我的帖子标记为已解决?@EricReboisson不需要ibm-web-bnd.xml,没有它,事情应该仍然可以进行。您能否更新您的问题,说明您如何尝试查找/注入数据源?以及你正在得到的错误我接受你的答案,即使问题是在其他地方…我明天会看一看,知道这个应用程序已配置。但它似乎是一个简单的webapp,具有标准的结构,正如我在主要帖子中所说的,当我添加ibm-web-bnd.xml文件时,它就像一个符咒一样工作;-)
<dataSource id="ds1" jndiName="jdbc/ds1">
    <properties ... />
    <jdbcDriver>
        <library>
            <fileset dir="${server.config.dir}/jdbcDrivers" includes="someJDBCDriver.jar"/>
        </library>
    </jdbcDriver>
</dataSource>