2016-01-12 93 views
2

是否可以將多個DataSource聲明爲Websphere Liberty Profile server.xml?任何例子?將多個DataSource轉換爲Websphere Liberty Profile

我嘗試做,但我只能看到一個。當第二個被查找時,我有一個錯誤信息,說沒有找到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> 

我只能看到DSPB在JConsole的觀點:http://i.stack.imgur.com/euN8e.jpg

怎麼了 ?

因此,IBM的web-bnd.xml失蹤,cheaty事...

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

埃裏克

回答

2

是的,這是可能的。只需在server.xml中指定單獨的<dataSource>元素即可。

例如:

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

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

注意,這兩個數據源具有jdbcDriverRef它們,其對應於一個<jdbcDriver>元件的ID。這很方便,因此每次要聲明<dataSource>時不必指定另一個JDBCDriver。

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

或者,您可以在數據源下窩<jdbcDriver>元素,如果你選擇。如果您從不在多個元素之間共享<jdbcDriver>,這將是理想選擇。

<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

+0

你好,謝謝你的回答,但根據你的解釋,我的配置仍然沒有工作,我加入了主要問題的更多信息。 –

+0

Pb解決了,ibm-web-bnd.xml丟失了,很難找到整個鏈來配置這兩個dataSources ... –

+0

我有什麼要做的事來標記我的帖子是否已解決? –

相關問題